How to compress log files using NLog

I am using NLog in one of my projects and I am trying to compress the output of files. I tried to use the compression file attribute, but when I look at the files, they are not compressed.

Could you tell me what I can do wrong?

This is my configuration:

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <targets>  
        <target name="file" xsi:type="File" fileName="C:\Workspaces\log.xml"
                layout="${message}" keepFileOpen="true"
                archiveFileName = "C:\Workspaces\archived\log.{#####}.xml"
                archiveAboveSize = "1048576" archiveNumbering = "Sequence"
                fileAttributes="Compressed" concurrentWrites =  "true"/>
    </targets>

    <rules>
        <logger name ="*" minlevel="Debug" writeTo="file" />
    </rules>
</nlo

g>

+6
source share
1 answer

With NLog 4 you can compress to zipfiles (.NET 4.5+). See NLog 4.0 Release Message

Use enableArchiveFileCompressionas follows:

<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" />
+5
source

All Articles