【发布时间】:2019-09-02 03:22:29
【问题描述】:
我希望我的日志根据其级别保存在不同的文件夹中。我希望这个配置完全通过配置文件而不是hard-coded configs,因为它将来可能会改变。在NLogconfiguration file 中这样做很容易,但我没有找到如何在Serilog 中进行高级日志配置。有什么建议吗?
目前我有这个:
"Serilog": {
"Using": [ "Serilog.Sinks.Console" ],
"MinimumLevel": "Information",
"Override": {
"Microsoft": "Warning",
"System": "Warning"
},
"WriteTo": [
{ "Name": "Console" },
{
"Name": "File",
"Args": {
"path": "logs\\AppLogs_.txt",
"rollingInterval": "Hour",
"fileSizeLimitBytes": 15000000,
"rollOnFileSizeLimit": true,
"shared": true,
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [{Level}]) {Message} {NewLine} {Exception}"
}
}
],
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ]
}
【问题讨论】:
-
您可以根据documentation在每个接收器级别上覆盖它
-
@SimplyGed,这是一个代码更改,正如我所说,我想在配置中按级别配置它,我没有找到每个级别配置的示例配置文件
-
您是否尝试将
"restrictedLevelMinimum": "Debug"添加到配置Args? -
另外,正如该文档所说,您不能在每个接收器的基础上更改配置级别:来自文档
the logger-level configuration controls which logging statements will result in the creation of events, while the sink-level configuration only filters these. To create a single logger with a more verbose level, use a separate LoggerConfiguration. -
restrictedLevelMinimum没用