Using date named archives together with archiveAboveSize parameter

205 views Asked by At

Using nlog 4.7.2.11786. Same behavior with the latest version - 4.7.10.13013.

I use archiveAboveSize to invoke archiving when log file reaches set size. All logs from a single day needs to be stored in the same archive.

However old data is just overridden inside an archive when archiving occurs multiple times a day as it is archiving files with the same name.

For example, there is a file debugLog_2021-06-07.log. When it reaches 10 MB size, it's compressed and added to new file debugLog_Archive_20210607.zip. After that zip file will have debugLog_2021-06-07.log inside.

I see multiple ways to handle this problem, but can't find a way to achieve them.

  1. If filename is already present in the archive, increment it's name.

  2. If filename is already present in the archive, append file.

Is any of this is currently supported by NLog?

My configuration:

<?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"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false"
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log">

<variable name="myvar" value="myvalue"/>
<variable name="fileDir" value="C:\logfolder\"/>
<variable name="archiveAboveSize" value="10485760"/> <!-- 10 MB -->
<variable name="maxArchiveFiles" value="10"/>

<targets>
<target xsi:type="File" name="logTarget" 
    fileName="${fileDir}\debugLog_${shortdate}.log"
    layout="${longdate} ${level}: ${message}"
    archiveFileName="${fileDir}\debugLog_Archive_{######}.zip"
    archiveAboveSize="${archiveAboveSize}"
    archiveNumbering="Date"
    maxArchiveFiles="${maxArchiveFiles}"
    enableArchiveFileCompression="True"
/>
</targets>

<rules>
<logger name="*" minlevel="Debug" writeTo="logTarget" />
</rules>
</nlog>
0

There are 0 answers