英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论