如何使用NLog压缩日志文件

Sys*_*der 7 compression nlog

我在我的一个项目中使用NLog,我正在尝试压缩文件的输出.我尝试使用compress文件属性,但是当我查看文件时,它们不会被压缩.

你能告诉我我可能做错了什么吗?

这是我的配置:

<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> 
Run Code Online (Sandbox Code Playgroud)

克>

Jul*_*ian 6

使用NLog 4,您可以压缩到zip文件(.NET 4.5+)。请参阅NLog 4.0版本发布

用法enableArchiveFileCompression如下:

<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" />
Run Code Online (Sandbox Code Playgroud)