Serilog 结构化数据漂亮打印?

Serilog structured data pretty print?

有没有办法把Serilog格式的结构化数据变成格式化输出?

我最近一直在使用 Serilog 中的结构化数据结构,尽管它具有紧凑的优点,但大型数据结构(5 个属性或更多)在不格式化的情况下很难在 console/file 中读取稍后。

假设我只会在开发人员上启用它。

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

来自这里:

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

为此:

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

编辑: 目前我正在使用 JsonConvert.SerializeObject({...}, Formatting.Indented),但出于控制台包的正确着色、更快的序列化、延迟序列化等原因,我想放弃它。

我似乎记得几年前我们不得不在工作中做一个自定义格式化程序来修改 serilog 的默认 json 输出。我不记得我们遇到的确切问题。

你可以看看,https://github.com/serilog/serilog/wiki/Formatting-Output,如果你还没有

我已经开始使用https://getseq.net/来查看开发过程中的结构化输出,我强烈推荐它。