nLog archiveEvery x Minutes

会有一股神秘感。 提交于 2020-01-05 12:09:16

问题


I would like to be able to archive logs on a 2 minute interval instead of a 1 minute, is this possible with the target NLog.config structure?

Poking around, I have set the following options:

archiveEvery="Minute" maxArchiveFiles="5"

Looking for a parameter or a way of doing archiveEvery="2minutes"


回答1:


FileArchivePeriod has a limited number of options.

 public enum FileArchivePeriod
 {
    /// <summary>
    /// Don't archive based on time.
    /// </summary>
    None,

    /// <summary>
    /// Archive every year.
    /// </summary>
    Year,

    /// <summary>
    /// Archive every month.
    /// </summary>
    Month,

    /// <summary>
    /// Archive daily.
    /// </summary>
    Day,

    /// <summary>
    /// Archive every hour.
    /// </summary>
    Hour,

    /// <summary>
    /// Archive every minute.
    /// </summary>
    Minute
}

These all have a related formatString that the FileTarget class uses as a simple greater than comparison mechanism to see if a new file should be created.

if (this.ArchiveEvery != FileArchivePeriod.None)
{
    string formatString = GetDateFormatString(string.Empty); //This is different per period type
    string ts = lastWriteTime.ToString(formatString, CultureInfo.InvariantCulture);
    string ts2 = ev.TimeStamp.ToLocalTime().ToString(formatString, CultureInfo.InvariantCulture);

    if (ts != ts2)
    {
        return true;
    }
}

So while you could definitely customize the code to meet your requirement, it won't do it out of the box (and the simple change would be kind of ugly, IMO).



来源:https://stackoverflow.com/questions/23273578/nlog-archiveevery-x-minutes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!