简体   繁体   English

NLog zip压缩并删除旧的日志文件

[英]NLog zip and delete old log files

I would like to have NLog automatically zip and delete log files older than two weeks. 我想让NLog自动压缩并删除超过两周的日志文件。 I know about the archiving features. 我知道存档功能。 I would like to extend them to check for two weeks old logs and automatically zip and delete them. 我想扩展它们以检查两个星期的日志,然后自动将其压缩并删除。

Solution: 解:

<targets>
    <target name="..." xsi:type="File"
        ...
        archiveFileName="debug{#}.log"
        archiveEvery="Day"
        archiveNumbering="Rolling"
        maxArchiveFiles="14"
        ... />
</targets>

See NLog built-in archiving "Archival Options" ( https://github.com/nlog/NLog/wiki/File-target ) 请参阅NLog内置存档“存档选项”( https://github.com/nlog/NLog/wiki/File-target

I can't find anything in documentation about NLog supporting .zip file creation. 我在有关支持.zip文件创建的NLog的文档中找不到任何内容。

Create a helper utility to run periodically. 创建一个帮助程序实用程序以定期运行。 Give it the path of your log file directory to find & zip files with time signatures matching your desired attributes. 为它提供日志文件目录的路径,以查找和压缩具有与所需属性匹配的时间戳的zip文件。 Keep a cache of the file names and then delete the files you have zipped. 保留文件名的缓存,然后删除已压缩的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM