<!-- enable asp.net core layout renderers --> <extensions> <addassembly="NLog.Web.AspNetCore"/> </extensions>
<!-- the targets to write to --> <targets> <!-- File Target for all log messages with basic details --> <targetxsi:type="File"name="allfile"fileName="\%TEMP%\nlog-AspNetCore-all-${shortdate}.log" layout="${longdate}|${event-properties:item=EventId:whenEmpty=0}|${level:uppercase=true}|${logger}|${message} ${exception:format=tostring}" />
<!-- File Target for own log messages with extra web details using some ASP.NET core renderers --> <targetxsi:type="File"name="ownFile-web"fileName="c:\temp\nlog-AspNetCore-own-${shortdate}.log" layout="${longdate}|${event-properties:item=EventId:whenEmpty=0}|${level:uppercase=true}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}" />
<!--Console Target for hosting lifetime messages to improve Docker / Visual Studio startup detection --> <targetxsi:type="Console"name="lifetimeConsole"layout="${MicrosoftConsoleLayout}" /> </targets>
<!-- rules to map from logger name to target --> <rules> <!--All logs, including from Microsoft--> <loggername="*"minlevel="Trace"writeTo="allfile" />
<!--Output hosting lifetime messages to console target for faster startup detection --> <loggername="Microsoft.Hosting.Lifetime"minlevel="Info"writeTo="lifetimeConsole, ownFile-web"final="true" />
<!--Skip non-critical Microsoft logs and so log only own logs (BlackHole) --> <loggername="Microsoft.*"maxlevel="Info"final="true" /> <loggername="System.Net.Http.*"maxlevel="Info"final="true" />
<!-- minlevel="Info"则不会输出Trace和Debug日志 --> <!-- rules to map from logger name to target --> <rules> <!--All logs, including from Microsoft--> <loggername="*"minlevel="Info"writeTo="allfile" />
<!--Output hosting lifetime messages to console target for faster startup detection --> <loggername="Microsoft.Hosting.Lifetime"minlevel="Info"writeTo="lifetimeConsole, ownFile-web"final="true" />
<!--Skip non-critical Microsoft logs and so log only own logs (BlackHole) --> <loggername="Microsoft.*"minlevel="Info"final="true" /> <loggername="System.Net.Http.*"minlevel="Info"final="true" />