How to configure Serilog.Exceptions.SqlServer in appsettings.json

736 views Asked by At

I'm using appsettings.json to configure Serilog. I added Serilog.Exceptions, which works like a charm.

"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" ]
}

But since I'm using Sql Server and EF Core, the documentation says I also have to configure Serilog.Exceptions.SqlServer and Serilog.Exceptions.EntityFrameworkCore.

According to this documentation this has to be added to the enrichter. In C# code this would be:

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

I can't figure out how to do that in appsettings.json. Can anyone help me with that?

1

There are 1 answers

0
Arjan On

This isn't possible at the moment, although the author is open for a PR if someone implements it.

See this issue, this discussion and this related question.