简体   繁体   English

NLog日志文件未压缩但被删除

[英]NLog log files not getting compressed but gets deleted

I am trying to zip and archive the old logs. 我正在尝试压缩和存档旧日志。 I used the below target for this purpose. 为此,我使用了以下目标。

<target name="PluginError" xsi:type="File" 
        layout="${longdate}${message}${exception:format=tostring}" 
        fileName="${basedir}/logs/Plugin/Error/${date:format=yyyy-MM-dd}.log" 
        archiveAboveSize="2000000" 
        archiveNumbering="Rolling" 
        maxArchiveFiles="10"  
        archiveFileName="${basedir}/logs/Plugin/Error/log.{#}.txt"             
        archiveEvery="Day"
        enableArchiveFileCompression="true"/>

But this deletes the old log files when count passes 3 instead of zipping them and archiving them. 但这会在count超过3时删除旧的日志文件,而不是将它们压缩并存档。 I am using NLog dll version 4.4.4090.0. 我正在使用NLog dll版本4.4.4090.0。 What am I doing wrong here? 我在这里做错了什么? Any help would be much appreciated. 任何帮助将非常感激。

The configuration you have specified will ensure: 您指定的配置将确保:

  • maxArchiveFiles="10" - Max 10 files in archive-folder. maxArchiveFiles =“ 10” -归档文件夹中最多10个文件。
  • archiveEvery="Day" - Will move the current log-file to the archive-folder once a day. archiveEvery =“ Day” -每天一次将当前日志文件移动到存档文件夹。
  • archiveAboveSize="2000000" - Will move the current log-file to the archive-folder if it grows beyond 2 MByte. archiveAboveSize =“ 2000000” -如果当前日志文件的大小超过2 MB,则将其移动到存档文件夹中。
  • archiveNumbering="Rolling" - Will ensure the lowest number (0) is the latest file. archiveNumbering =“ Rolling” -将确保最低编号(0)是最新文件。
  • archiveFileName="${basedir}/logs/Plugin/Error/log.{#}.txt" - Will rename the current log-file from log.0.txt to log.9.txt . archiveFileName =“ $ {basedir} / logs / Plugin / Error / log。{#}。txt” -将当前日志文件从log.0.txt重命名为log.9.txt
  • enableArchiveFileCompression="true" - Will compress each individual file using ZIP-format. enableArchiveFileCompression =“ true” -将使用ZIP格式压缩每个文件。 Consider to change archiveFileName to have ZIP extension to match this decision. 考虑将archiveFileName更改为具有ZIP扩展名以匹配此决定。

If it behaves differently, then please try and change archiveEvery to Minute . 如果行为不同,请尝试将archiveEvery更改为Minute If it continues to only have 3 files in the archive-folder, then please tell. 如果归档文件夹中仍然只有3个文件,请告知。 Else I think some scheduled-task is cleaning up the archives-folder (or you have several NLog-file-targets pointing to the same folder?). 另外,我认为某些计划任务正在清理存档文件夹(或者您有几个指向同一文件夹的NLog文件目标?)。

Maybe also check if you have any files in the Error-folder, that matches the wildcard log*.txt 也许还检查错误文件夹中是否有任何与通配符log * .txt相匹配的文件

i think there you are missing 我想你在那里失踪了

enableArchiveFileCompression="true" 

you can use this nlog configuration its working fine http://nlog-project.org/2015/06/09/nlog-4-has-been-released.html 您可以使用此nlog配置正常运行http://nlog-project.org/2015/06/09/nlog-4-has-been-released.html

<?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" autoReload="true">
  <targets >
   <target name="file" xsi:type="File"
  layout="${longdate} ${logger} ${message}" 
  fileName="${basedir}/logs/logfile.txt" 
  archiveFileName="${basedir}/archives/log.{#}.txt"
  archiveEvery="Day"
  archiveNumbering="Rolling"
  maxArchiveFiles="7"
enableArchiveFileCompression="true" />
  </targets>
  <rules>
    <logger name="*" minlevel="Debug" writeTo="logfile">
    </logger>
  </rules>
</nlog>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM