When using nlog in .netcore application, I found out a very strange thing: When using VisualStudio to debug the application, the nlog works perfect. I set the minloglevel in nlog.config to Debug:
However, when deployed to server, the log only shows level equals or greater than Warning. I have also set the minlevel in program.cs file and it is still output Trace, Debug and Information log:
<rules> <!--Skip Microsoft logs and so log only own logs--> <logger name="Microsoft.*" minlevel="Trace" writeTo="blackhole" final="true" /> <!--All logs, including from Microsoft--> <!--<logger name="*" minlevel="Warn" writeTo="console" /> --> <logger name="*" minlevel="Debug" writeTo="applog" /> </rules>
However, when deployed to server, the log only shows level equals or greater than Warning. I have also set the minlevel in program.cs file and it is still output Trace, Debug and Information log:
.ConfigureLogging((host, builder) => { host.HostingEnvironment.ConfigureNLog("nlog.config"); builder.SetMinimumLevel(LogLevel.Debug); })After lots of search, someone suggested to change the LogLevel in appsettings.json file as well. The original value is Warning. After I changed it to Debug, the application finally output Debug and Information logs.
"Logging": { "IncludeScopes": false, "LogLevel": { "Default": "Debug" }
Comments