NLog生成了太多的归档文件。

huangapple go评论57阅读模式
英文:

NLog generates too many archives

问题

我是使用以下方式配置NLog的:

var logfile = new NLog.Targets.FileTarget("logfile")
{
    FileName = Path.Combine(_logDirectory, "myApp.log"),
    Layout = "${date} [${level}] ${message} ${exception}${newline}",
    ArchiveFileName = Path.Combine(_logDirectory, "myApp.{#}.log"),
    ArchiveAboveSize = 100 * 1024, MaxArchiveFiles = 9
};

file target syntax documentation上说明,ArchiveFileName属性中的{#}字符数量用于确定数字的位数。正如您所看到的,我只放了一个井号字符,但结果是我得到了一个超过myApp.9.log的存档,它很容易超过.100。
我做错了什么?

感谢您的帮助。

英文:

I'm using NLog configured this way:

var logfile = new NLog.Targets.FileTarget("logfile")
{
    FileName = Path.Combine(_logDirectory, "myApp.log"),
    Layout = "${date} [${level}] ${message} ${exception}${newline}",
    ArchiveFileName = Path.Combine(_logDirectory, "myApp.{#}.log"),
    ArchiveAboveSize = 100 * 1024, MaxArchiveFiles = 9
};

On the file target syntax documentation it says that the number of {#} characters in the ArchiveFileName property are used to determine the number of digits. As you can see I've only put one hash character but the result is that I'm getting an archiving that goes way beyond myApp.9.log, it can easily reach past .100.
What am I doing wrong?

Thanks for your help

答案1

得分: 1

我猜你想要滚动文件名。尝试添加 ArchiveNumbering = NLog.Targets.ArchiveNumberingMode.Rolling

参见 https://github.com/NLog/NLog/wiki/FileTarget-Archive-Examples

英文:

I'm guessing that you want rolling filenames. Try adding ArchiveNumbering = NLog.Targets.ArchiveNumberingMode.Rolling.

See also https://github.com/NLog/NLog/wiki/FileTarget-Archive-Examples

huangapple
  • 本文由 发表于 2023年7月31日 23:17:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76804987.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定