JSON Configuration for Serilog.Exception destructurers
Asked Answered
B

1

2

I am adding Serilog to the project and I specifically want to add Serilog.Exceptions as well. Following the guideline I've added just the Exceptions enricher successfully, but I also need the destructures mentioned in the linked page.

The following works fine using fluent configuration:

config.Enrich.WithExceptionDetails(new DestructuringOptionsBuilder()
    .WithDefaultDestructurers()
    .WithDestructurers(new ExceptionDestructurer[]
    {
        new DbUpdateExceptionDestructurer(),
        new SqlExceptionDestructurer()
    }));

However, I'm struggling to get it configured using JSON config like this:

config.ReadFrom.Configuration(context.Configuration);

Here's what I've tried already without much luck:

"Enrich": [
      { "Name": "FromLogContext" },
      {
        "Name": "WithExceptionDetails",
        "Args": {
          "With": "DbUpdateException, SqlException"
        }
      } 
]

and also:

"Enrich": [ "FromLogContext", "WithExceptionDetails" ],
"Destructure": [
      {
        "Name": "With",
        "Args": { "policy": "DbUpdateException, SqlException" }
      }
]

How do I configure the fluent version using JSON?

Bengaline answered 28/10, 2019 at 8:27 Comment(3)
It seems it is impossible to configure Destructure from Configuration, try to refer Add support for serilog-settings-configuration #58Pericycle
@TaoZhou, thanks for the link. Yeah I resorted to configure it using code as well. You can post an answer if you want, so this question can be actually closedBengaline
Since version 3.0.0 of github.com/serilog/serilog-settings-configuration there is now support for Destructure from config.Consume
P
1

Currently, it is not supported to configure Destructure from Configuration which is by design.

It is recommended to configure through code.

Reference : Add support for serilog-settings-configuration #58

Pericycle answered 30/10, 2019 at 9:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.