NLog rotate and cleanup logfiles

前端 未结 2 1598
生来不讨喜
生来不讨喜 2020-12-13 18:54

Within my company we\'re working with NLog. We\'re experiencing issues with large amount of log files. What we want to do is archive files by day and keep a maximum of an x

相关标签:
2条回答
  • 2020-12-13 19:21

    NLog 4.5 (and newer) improves the support for dynamic fileName-Layout and archive-logic.

    You can do this:

        <target name="file" xsi:type="File"
            fileName="${basedir}/logs/Log.${level}.${shortdate}.txt"
            archiveAboveSize="5242880"
            maxArchiveFiles="3" />
    

    NLog 4.7 also introduces the setting maxArchiveDays for the FileTarget.

    See also https://github.com/NLog/NLog/wiki/File-target#archive-old-log-files

    0 讨论(0)
  • 2020-12-13 19:27

    It looks like the problem is the shortdate in your filename definition. See my answer at this question: Delete log files after x days

    You have to define the filename without the date part

    fileName="${basedir}/logs/Log.info.txt
    
    0 讨论(0)
提交回复
热议问题