6

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.

Pavel
  • 653
  • 2
  • 11
  • 31

1 Answers1

7

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))
Martin Liversage
  • 104,481
  • 22
  • 209
  • 256