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"

有帮助吗?

解决方案

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).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top