nLog存档每x分钟 [英] nLog archiveEvery x Minutes

查看:191
本文介绍了nLog存档每x分钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够以2分钟的间隔而不是1分钟的时间来归档日志,这可以通过目标NLog.config结构实现吗?

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 =分钟" maxArchiveFiles ="5"

archiveEvery="Minute" maxArchiveFiles="5"

寻找参数或做归档的方式Every ="2minutes"

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

推荐答案

FileArchivePeriod具有有限数量的选项.

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
}

所有这些都具有相关的formatStringFileTarget类将其用作简单的大于比较机制,以查看是否应创建新文件.

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;
    }
}

因此,尽管您绝对可以自定义代码来满足您的要求,但它并不能即开即用(而简单的更改将非常难看,IMO).

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

这篇关于nLog存档每x分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆