0

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. I am using NLog dll version 4.4.4090.0. What am I doing wrong here? Any help would be much appreciated.

Julian
  • 33,915
  • 22
  • 119
  • 174
AnOldSoul
  • 4,017
  • 12
  • 57
  • 118

2 Answers2

1

The configuration you have specified will ensure:

  • maxArchiveFiles="10" - Max 10 files in archive-folder.
  • archiveEvery="Day" - Will move the current log-file to the archive-folder once a day.
  • archiveAboveSize="2000000" - Will move the current log-file to the archive-folder if it grows beyond 2 MByte.
  • archiveNumbering="Rolling" - Will ensure the lowest number (0) is the latest file.
  • archiveFileName="${basedir}/logs/Plugin/Error/log.{#}.txt" - Will rename the current log-file from log.0.txt to log.9.txt.
  • enableArchiveFileCompression="true" - Will compress each individual file using ZIP-format. Consider to change archiveFileName to have ZIP extension to match this decision.

If it behaves differently, then please try and change archiveEvery to Minute. If it continues to only have 3 files in the archive-folder, then please tell. Else I think some scheduled-task is cleaning up the archives-folder (or you have several NLog-file-targets pointing to the same folder?).

Maybe also check if you have any files in the Error-folder, that matches the wildcard log*.txt

Rolf Kristensen
  • 17,785
  • 1
  • 51
  • 70
0

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

<?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>
Ravi Kanth
  • 1,182
  • 13
  • 38
  • That's not needed: "Compressed - Compress won't work due to .Net restrictions. You can use enableArchiveFileCompression." https://github.com/nlog/nlog/wiki/File-target – Julian Mar 15 '17 at 14:25