JSON Configuration for Serilog.Exception destructurers

1.9k views Asked by At

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?

1

There are 1 answers

0
Edward On BEST ANSWER

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