【发布时间】:2019-03-10 10:06:23
【问题描述】:
我使用NLog 在单独的文件中登录我的 ASP.NET Core 项目:
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets async="true">
<target name="JsonFile" xsi:type="File" layout="${message}" fileName="${shortdate}Json.log"/>
<target name="ServerFile" xsi:type="File" layout="${message}" fileName="${shortdate}Server.log"/>
</targets>
<rules>
<logger name="JsonLog" minlevel="Debug" writeTo="JsonFile" />
<logger name="ServerLog" minlevel="Debug" writeTo="ServerFile" />
</rules>
</nlog>
-
public static class Log
{
public static Logger Json = LogManager.GetLogger("JsonLog");
public static Logger Server = LogManager.GetLogger("ServerLog");
}
我的问题:
1.我可以将ASP.NET Core的消息直接记录到NLog的具体ServerLog文件中吗?
2. 我是否可以避免 ASP.NET Core 想要同步登录到控制台,而只使用 NLog 的异步 ServerLog 文件以获得更好的性能?广泛的控制台日志记录对 API 的性能产生了巨大的影响。
【问题讨论】:
标签: c# logging asp.net-core nlog