我们使用 Nlog 作为我们的日志记录框架,但我找不到按我想要的方式归档文件的方法。我想在日志文件名中记录发生日志的日期。
Ex 所有发生的日志记录2009-10-01 00:00 -> 2009-10-01:23:59
都应该放在Log.2009-10-01.log
. 但是这一天的所有原木都应该放在Log.log
尾矿之类的地方。
我使用的当前 NLog.config 看起来像这样。
<?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" >
<extensions>
<add assembly="My.Awesome.LoggingExentions"/>
</extensions>
<targets>
<target name="file1" xsi:type="File"
fileName="${basedir}/Logs/Log.log"
layout="${longdate} ${level:uppercase=true:padding=5} ${session} ${storeid} ${msisdn} - ${logger:shortName=true} - ${message} ${exception:format=tostring}"
archiveEvery="Day"
archiveFileName="${basedir}/Logs/Log${shortdate}-{#}.log"
archiveNumbering="Sequence"
maxArchiveFiles="99999"
keepFileOpen="true"
/>
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="file1" />
</rules>
</nlog>
但是,这会将日志文件中的日期设置为创建新日志文件的日期。当您想稍后阅读日志时,这会导致沮丧。
似乎我必须在archiveFileName 中至少有一个#,我宁愿不要。因此,如果您对此有解决方案,我也会感激不尽 =)