I have following logger configuration
new LoggerConfiguration()
  .ReadFrom.Configuration(configuration.GetSection("MyConfig"))
  .WriteTo.Console(new CompactJsonFormatter())
  .Destructure.UsingAttributes()
  .Enrich.WithProperty("CorrelationIdHeader", "someId")
  .CreateLogger()
I'm executing:
logger.Information("{@MyObject}", new MyObject {SomeVal = ""});
Console output json always contains $type property, which I would like to remove
{
  ...
  "$type": "MyObject"
}
How would I remove $type during configuration? Thanks.
You need to construct the CompactJsonFormatter with a JsonValueFormatter that doesn't output the type. You can do that by specifying null as the typeTagName when creating the JsonValueFormatter:
new CompactJsonFormatter(new JsonValueFormatter(null))
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With