【问题标题】:How to force NLog to overwrite the log file如何强制 NLog 覆盖日志文件
【发布时间】:2012-11-16 14:21:08
【问题描述】:

我需要 NLog 在应用程序重新启动时覆盖日志文件。目前它附加到现有文件。 例如,我的 NLog.config 中有类似的内容

<targets>
  <target xsi:type="File" name="fileLog" 
          fileName="${longdate}.log" layout="${message}" />
</targets>

如果我能够添加到 &lt;target&gt; 类似 append="false" 这样的内容会很好,而不是附加到现有日志,它会覆盖。

【问题讨论】:

    标签: .net nlog overwrite


    【解决方案1】:

    替换你的配置部分

    <targets>
      <target xsi:type="File" name="fileLog" 
              fileName="${longdate}.log" layout="${message}" deleteOldFileOnStartup="true"/>
    </targets>
    

    【讨论】:

    • deleteOldFileOnStartup 仅在“FileName”参数表示单个文件时有效。就我而言,它是 fileNmae="${longdate}.log"。在这种情况下,它不起作用。但是,对于我的应用程序。我可以更改日志文件的名称,这个解决方案对我有用。加 1,我会接受你的回答。
    • 文件多久被删除一次,基于什么,一天,一个月,文件大小?
    猜你喜欢
    • 2017-04-06
    • 1970-01-01
    • 2010-11-01
    • 1970-01-01
    • 2016-04-27
    • 1970-01-01
    • 2017-12-30
    相关资源
    最近更新 更多