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.
The configuration you have specified will ensure:
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
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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.