Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serilog structured data pretty print?

Is there a way to make Serilog format structured data into a formatted output?

I've been using structured data structures in Serilog lately and even though there is an advantage of it being compact large data structures (5 properties or more) are hard to read in the console/file without formatting it later.

Hypothetically I'd only enable this on dev.

https://github.com/serilog/serilog/wiki/Structured-Data

From this:

{ "Fruit": ["Apple", "Pear", "Orange"] }

To this:

{
  "Fruit": [
    "Apple",
    "Pear",
    "Orange"
  ]
}

Edit: Currently I'm using JsonConvert.SerializeObject({...}, Formatting.Indented) but I'd like to move away from this for reasons like proper coloring from the console package, faster serialization, deferred serialization etc.

like image 908
jeanfrg Avatar asked Jul 25 '17 20:07

jeanfrg


1 Answers

I seem to recall that we had to do a custom formatter at work a few years ago to modify the default json output from serilog. I do not remember the exact problem we had.

You could take a look at, https://github.com/serilog/serilog/wiki/Formatting-Output, if you haven't already

I have started using https://getseq.net/ to look at the structured output during development, I would highly recommend it.

like image 51
Christian Sparre Avatar answered Oct 19 '22 20:10

Christian Sparre