gpt4 book ai didi

c# - 为 serilog sink 指定更高的日志级别

转载 作者:行者123 更新时间:2023-12-04 07:51:41 26 4
gpt4 key购买 nike

我的 ASP.NET WEB API .NET Core 3 应用程序中有许多 Serilog 接收器。其中一个接收器是 MS SQL,我只想在其中写入错误消息。这是我的 appsettings.json 的一部分

"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.Debug", "Serilog.Sinks.File", "Serilog.Sinks.MSSqlServer" ],
"MinimumLevel": {
"Default": "Debug",
"Override": {
"Microsoft": "Information",
"System": "Information"
}
},
"WriteTo": [
{ "Name": "Console" },
{ "Name": "Debug" },
{
"Name": "File",
"Args": {
"path": "Logs/log_.txt",
"rollingInterval": "Minute",
"shared": true
}
},
{
"Name": "MSSqlServer",
"Args": {
"connectionString": "CONNECTIONSTRING",
"sinkOptionsSection": {
"tableName": "Logs",
"schemaName": "EventLogging",
"autoCreateSqlTable": true,
"batchPostingLimit": 50,
"restrictedToMinimumLevel": "Error",
"period": "0.00:00:30"
}
}
}
],
"Enrich": [ "FromLogContext", "WithMachineName" ]
}

但最终我在 SQL 日志记录表中得到了一些 Information 和 Debug 级别的消息。

上面的配置有什么问题?为什么 restrictedToMinimumLevel 没有帮助?

如果我想排除低于 Information 的消息,我必须在 MinimumLevel 部分的 Default 子部分中设置它。

但在这种情况下,我不允许为特定接收器指定较低级别的消息。例如

"restrictedToMinimumLevel":"Debug"

无济于事 - 调试消息不会写入 MS SQL。

最佳答案

restrictedToMinimumLevelArgs 的子项。检查docs .

尝试:

"WriteTo": [
{ "Name": "Console" },
{ "Name": "Debug" },
{
"Name": "File",
"Args": {
"path": "Logs/log_.txt",
"rollingInterval": "Minute",
"shared": true
}
},
{
"Name": "MSSqlServer",
"Args": {
"connectionString": "CONNECTIONSTRING",
"sinkOptionsSection": {
"tableName": "Logs",
"schemaName": "EventLogging",
"autoCreateSqlTable": true,
"batchPostingLimit": 50,
"period": "0.00:00:30"
},
"restrictedToMinimumLevel": "Error",
}
}
],

关于c# - 为 serilog sink 指定更高的日志级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66934788/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com