How to configure Serilog.Exceptions.SqlServer in appsettings.json
Asked Answered
U

1

6

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?

Unlay answered 16/12, 2019 at 8:51 Comment(0)
M
1

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.

Mullin answered 1/5, 2021 at 22:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.