Serilog.Sinks.Logz.Io icon indicating copy to clipboard operation
Serilog.Sinks.Logz.Io copied to clipboard

Writing context object as JSON object rather than flattened fields

Open hardcodet opened this issue 9 months ago • 1 comments

I would like to log additional structured content that complements the logged message like this:

Logger
    .ForContext("payload", new {FooBar = "xxx", BarFoo = "yyy"}, true)
    .Warning("hello world");

This gives me some JSON similar to this with flattened properties and wrong casing:

{
  "message": "hello world",
  "level": "warning",
  ...
  "payload.FooBar": "xxx",
  "payload.BarFoo": "yyy"
}

Is there a setting or an easy way to override a formatter in order to have the payload logged like this (object with camel casing like the rest)?

{
  "message": "hello world",
  "level": "warning",
  ...
  "payload": {
    "fooBar": "xxx",
    "barFoo": "yyy"
  }
}

Thanks for your advice :)

hardcodet avatar Jan 06 '25 14:01 hardcodet