NLog 存档配置
NLog Archive configuration
在我的一些程序中,我按预期进行了 30 天的轮换,其中包含几个月的多个条目,但只有 30 个日志文件。在其他程序中,我只有一天的日志文件,但总共只有 30 个日志文件。我想要的只是过去 30 天的日志文件条目和 30 个日志文件。我想我不知道我错过了什么。
昨天我的一个日志文件在程序启动备份时被覆盖,所以我丢失了可以告诉我发生了什么的数据。那么我的第二个问题是,归档只是删除不符合模式的文件,还是实际上获取日志文件并将它们放在某个地方?归档到底是什么?这是我的 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">
<!--
See https://github.com/nlog/nlog/wiki/Configuration-file
for information on customizing logging rules and outputs.
-->
<variable name="LogDir" value="${specialfolder:folder=MyDocuments}/MyApp/Log"/>
<variable name="LogDay" value="${date:format=dd}"/>
<targets async="true">
<!-- add your targets here -->
<target name="LogTarget1"
xsi:type="File"
fileName="${LogDay}.log"
encoding="utf-8"
maxArchiveFiles="30"
archiveNumbering="Sequence"
archiveAboveSize="52428800"
archiveFileName="${LogDay}.{#######}.log"
layout="${date:format=MM/dd/yyyy HH\:mm\:ss}|${level:uppercase=true}|${message}" />
</targets>
<rules>
<!-- add your logging rules here -->
<logger name="*" minlevel="Trace" writeTo="LogTarget1" />
</rules>
</nlog>
这是 NLog 的一个缺点,没有很好的记录。
当应删除文件时(例如最大存档文件),则日志文件和存档文件不能位于同一文件夹中。
因此,此配置的一个修复方法是将 archifeFilePath 更改为
archiveFileName="archive/${LogDay}.{#######}.log"
在我的一些程序中,我按预期进行了 30 天的轮换,其中包含几个月的多个条目,但只有 30 个日志文件。在其他程序中,我只有一天的日志文件,但总共只有 30 个日志文件。我想要的只是过去 30 天的日志文件条目和 30 个日志文件。我想我不知道我错过了什么。
昨天我的一个日志文件在程序启动备份时被覆盖,所以我丢失了可以告诉我发生了什么的数据。那么我的第二个问题是,归档只是删除不符合模式的文件,还是实际上获取日志文件并将它们放在某个地方?归档到底是什么?这是我的 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">
<!--
See https://github.com/nlog/nlog/wiki/Configuration-file
for information on customizing logging rules and outputs.
-->
<variable name="LogDir" value="${specialfolder:folder=MyDocuments}/MyApp/Log"/>
<variable name="LogDay" value="${date:format=dd}"/>
<targets async="true">
<!-- add your targets here -->
<target name="LogTarget1"
xsi:type="File"
fileName="${LogDay}.log"
encoding="utf-8"
maxArchiveFiles="30"
archiveNumbering="Sequence"
archiveAboveSize="52428800"
archiveFileName="${LogDay}.{#######}.log"
layout="${date:format=MM/dd/yyyy HH\:mm\:ss}|${level:uppercase=true}|${message}" />
</targets>
<rules>
<!-- add your logging rules here -->
<logger name="*" minlevel="Trace" writeTo="LogTarget1" />
</rules>
</nlog>
这是 NLog 的一个缺点,没有很好的记录。
当应删除文件时(例如最大存档文件),则日志文件和存档文件不能位于同一文件夹中。
因此,此配置的一个修复方法是将 archifeFilePath 更改为
archiveFileName="archive/${LogDay}.{#######}.log"