<?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"
autoReload="true"
internalLogLevel="Info"
internalLogFile="Logs/internal-nlog-AspNetCore.txt">
<!-- enable asp.net core layout renderers -->
<!--<extensions>
<add assembly="NLog.Web.AspNetCore"/>
</extensions>-->
<!-- the targets to write to -->
<targets async="true">
<!-- fileName 输出路径:Logs/2022/2022-10/10-08/error/nolog-error-10_11_15.txt -->
<!--cached:文件名配置,使用该关键字并在文件名中使用时间 ;archiveAbovesize="10485760" 文件最大字节数; maxArchiveFiles="100" 保留文件数量-->
<target xsi:type="File" name="errorfile" fileName="Logs/${date:format=yyyy}/${date:format=yyyy-MM}/${date:format=MM-dd}/error/nlog-error-${cached:${date:format=HH_mm_ss}}.txt"
layout="${longdate}|${event-properties:item=EventId:whenEmpty=0}|${level:uppercase=true}|${logger}|${message} ${exception:format=tostring}" maxArchiveFiles="100" archiveEvery="Minute " archiveAbovesize="10485760" />
<target xsi:type="File" name="warnfile" fileName="Logs/${date:format=yyyy}/${date:format=yyyy-MM}/${date:format=MM-dd}/warn/nlog-warn-${cached:${date:format=HH_mm_ss}}.txt"
layout="${longdate}|${event-properties:item=EventId:whenEmpty=0}|${level:uppercase=true}|${logger}|${message} ${exception:format=tostring}" maxArchiveFiles="100" archiveEvery="Minute " archiveAbovesize="10485760" />
<target xsi:type="File" name="infofile" fileName="Logs/${date:format=yyyy}/${date:format=yyyy-MM}/${date:format=MM-dd}/info/nlog-info-${cached:${date:format=HH_mm_ss}}.txt"
layout="${longdate}|${event-properties:item=EventId:whenEmpty=0}|${level:uppercase=true}|${logger}|${message} ${exception:format=tostring}" maxArchiveFiles="100" archiveEvery="Minute " archiveAbovesize="10485760" />
<target xsi:type="File" name="debugfile" fileName="Logs/${date:format=yyyy}/${date:format=yyyy-MM}/${date:format=MM-dd}/debug/nlog-debug-${cached:${date:format=HH_mm_ss}}.txt"
layout="${longdate}|${event-properties:item=EventId:whenEmpty=0}|${level:uppercase=true}|${logger}|${message} ${exception:format=tostring}" maxArchiveFiles="100" archiveEvery="Minute " archiveAbovesize="10485760" />
<!-- File Target for own log messages with extra web details using some ASP.NET core renderers -->
<target xsi:type="File" name="ownFile-web" fileName="Logs/${date:format=yyyy}/${date:format=yyyy-MM}/${date:format=MM-dd}/nlog-own.txt"
layout="${longdate}|${event-properties:item=EventId:whenEmpty=0}|${level:uppercase=true}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}|${callsite}" />
<!--Console Target for hosting lifetime messages to improve Docker / Visual Studio startup detection -->
<target xsi:type="Console" name="lifetimeConsole" layout="${MicrosoftConsoleLayout}" />
</targets>
<!-- rules to map from logger name to target -->
<rules>
<!--All logs, including from Microsoft-->
<logger name="*" writeTo="errorfile" levels="Error" />
<logger name="*" writeTo="warnfile" levels="Warn" />
<logger name="*" writeTo="infofile" levels="Info" />
<logger name="*" writeTo="debugfile" levels="Debug" />
<!--Output hosting lifetime messages to console target for faster startup detection -->
<logger name="Microsoft.Hosting.Lifetime" minlevel="Info" writeTo="lifetimeConsole, ownFile-web" final="true" />
<!--Skip non-critical Microsoft logs and so log only own logs (BlackHole) -->
<logger name="Microsoft.*" maxlevel="Info" final="true" />
<logger name="System.Net.Http.*" maxlevel="Info" final="true" />
<!--<logger name="*" minlevel="Trace" writeTo="ownFile-web" />-->
</rules>
</nlog>
标签:layout,配置文件,longdate,uppercase,路径,nlog,whenEmpty,true,event From: https://www.cnblogs.com/liujianshe1990-/p/16768385.html