2016-11-16 84 views
2

在我的一些程序中,我有30天的轮转,预计有几个月的多个条目,但只有30个日志文件。在其他程序中,我只有一天的日志文件,但总共只有30个日志文件。我想要的仅仅是最近30天的30个日志文件的日志文件条目。我想我不知道我错过了什么。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"> 

    <!-- 
    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> 

回答

2

这是NLog的一个缺点,没有很好的记录。

当应删除文件(例如,max archives文件)时,日志文件和存档文件不能位于同一文件夹中。

所以一个修复了该配置是将archifeFilePath改变也

archiveFileName="archive/${LogDay}.{#######}.log" 

this issue on GitHub