我正在使用 appsettings.json 来配置 Serilog。我补充说Serilog.Exceptions
,这就像一个魅力。
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Settings.Configuration", "Serilog.Exceptions" ],
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"System": "Warning"
}
},
"WriteTo": [
{ "Name": "Console" },
{
"Name": "File",
"Args": {
"path": "%TEMP%\\Logs\\serilog-configuration-sample.txt",
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception} {Properties:j}",
"rollingInterval": "Day"
}
}
],
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId", "WithExceptionDetails" ]
}
但由于我使用的是 Sql Server 和 EF Core,文档说我还必须配置Serilog.Exceptions.SqlServer
和Serilog.Exceptions.EntityFrameworkCore
.
根据此文档,这必须添加到浓缩器中。在 C# 代码中,这将是:
.Enrich.WithExceptionDetails(new DestructuringOptionsBuilder()
.WithDefaultDestructurers()
.WithDestructurers(new[] { new SqlExceptionDestructurer() }))
我无法弄清楚如何在appsettings.json
. 任何人都可以帮助我吗?