简体   繁体   中英

NLog zip and delete old log files

I would like to have NLog automatically zip and delete log files older than two weeks. 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 )

I can't find anything in documentation about NLog supporting .zip file creation.

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. Keep a cache of the file names and then delete the files you have zipped.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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