How do you configure Destructurama.Attributes .Destructure.UsingAttribues() in JSON from appsettings?

Viewed 563

We use appsettings to configure Serilog via JSON, a fairly standard enterprise practice. But I'm having trouble enabling the UsingAttributes. How does one enable .Destructure.UsingAttributes via JSON config?

I started with a pure Serliog approach, but they indicate that Serilog.Extras.Attributed is deprecated in favor of using Destructurama.Attributed. And in looking at the Destructurama.Attributed github example, I don't understand how to convert that into a JSON configuration. Their example:

var log = new LoggerConfiguration().Destructure.UsingAttributes()

The Serilog documentation for the "Destructure" option is straightforward:

"Destructure": [
  {
    "Name": "With",
    "Args": { "policy": "Sample.CustomPolicy, Sample" }
  },
 ],

However, I don't know what I would use for the "Sample.CustomPolicy, Sample" to get Destructurama to be enabled.

"Destructure": [
  {
    "Name": "With",
    "Args": { "UsingAttributes": WHAT_GOES_HERE}
  },
 ],

I feel like I'm missing something obvious.

1 Answers

I just encountered the same problem and after a few experiments I figured how to have it working using Destructurama.Attributed version 2.0.0 :

  1. You must specify the following using in JSON configuration to make Serilog able to see the library :
"Serilog":
{
  "Using":
  [
    "Destructurama.Attributed"
  ],
   ....
}
  1. Inside Serilog configuration, you have to specify this to Destructure to enable the attributes :
"Destructure":
[
  {
      "Name": "UsingAttributes"
  },
  ....
]
Related