我們使用Nlog作爲我們的日誌框架,並且找不到一種按照自己想要的方式歸檔文件的方法。我想記錄日誌文件名中的日期。
Ex所有從2009-10-01 00:00 -> 2009-10-01:23:59
發生的日誌記錄應放置在Log.2009-10-01.log
中。但是這一天的所有日誌都應該放在Log.log
之內,用於拖尾等。如何讓Nlog將文件與日誌發生日期進行歸檔
我使用的當前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至少有一個#,而我不喜歡。所以,如果你有一個解決方案,我也會感謝兩倍=)
對不起返回到很老的線程文件夾Log.log ...但你有沒有找到一個解決這個? – 2015-02-28 16:42:37
@AndrewJones沒有。我已經轉向了彈性/ logstash和kibana堆棧。 – 2015-03-01 17:05:06