2
我正在使用NLog.Logging.Extensions編寫一個asp.net核心應用程序來提供日誌記錄。ASP.NET Core NLog nlog.config加載但忽略
登錄報名:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) {
loggerFactory.AddNLog();
loggerFactory.ConfigureNLog("nlog.config");
loggerFactory.AddConsole();
loggerFactory.AddDebug();
app.UseMvc();
}
我越來越日誌輸出,但它不匹配在config文件中定義我的記錄佈局的格式,它並沒有顯示下面的信息什麼(但是,它又被配置爲在配置文件中顯示trace和above)。
是否有人能夠解釋爲什麼這可能會發生?
nlog.config:
<?xml version="1.0" encoding="utf-8"?>
<nlog>
<variable name="Layout" value="${longdate} ${level:upperCase=true} ${message} (${callsite:includSourcePath=true})${newline}${exception:format=ToString}"/>
<targets>
<target name="debugger" type="Debugger" layout="${Layout}" />
<target name="console" type="ColoredConsole" layout="${Layout}" detectConsoleAvailable="False"/>
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="debugger,console" />
</rules>
</nlog>
示例日誌輸出:
Hosting environment: Development
Content root path: /Users/###/dev/###/Services/src/app/###/###
Now listening on: http://localhost:8888 Application started.
Press Ctrl+C to shut down.
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET http://localhost:8888/State
info: ###.###.###[0]
Building ### instance.
注:調試目標不在netstandard可用,見https://github.com/NLog/NLog/wiki/platform -支持 – Julian