I am using NLog in one of my projects and I am trying to have the output of the files to be compressed. I tried to use the compress file attribute, but when I look at the files, they are not compressed.
Could you please tell me what I might be doing wrong?
This is my config:
<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>
</nlog>
With NLog 4, you can compress to zip
files (.NET 4.5+). See the NLog 4.0 release post
Use enableArchiveFileCompression
as 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" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With