0

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>
InfernumDeus
  • 1,185
  • 1
  • 11
  • 33
  • 1
    You are mixing dynamic-archive-mode `fileName="debugLog_${shortdate}.log"` with static-archive-mode `archiveFileName="debugLog_Archive_{######}.zip"`. Please choose one. See also https://github.com/nlog/NLog/wiki/File-target#dynamic-vs-static-archive-logic – Rolf Kristensen Jun 07 '21 at 18:38
  • 1
    I think NLog FileTarget does not have support for appending multiple files from the same day in the same zip-file. You are ofcourse wellcome to create a pull-request for fixing this. – Rolf Kristensen Jun 07 '21 at 18:42

0 Answers0