如何在appsettings.json中配置Serilog.Exceptions.SqlServer

时间:2019-12-16 08:51:04

标签: serilog serilog-exceptions

我正在使用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,documentation说我还必须配置Serilog.Exceptions.SqlServerSerilog.Exceptions.EntityFrameworkCore

根据本文档,必须将其添加到浓缩器中。在C#代码中,这将是:

.Enrich.WithExceptionDetails(new DestructuringOptionsBuilder()
    .WithDefaultDestructurers()
    .WithDestructurers(new[] { new SqlExceptionDestructurer() }))

我不知道如何在appsettings.json中做到这一点。有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

目前这是不可能的,尽管如果有人实施它,作者可以接受 PR。

参见 this issuethis discussionthis related question