Serilog结构化数据漂亮打印?

jea*_*frg 5 c# logging serilog .net-core asp.net-core

有没有办法将Serilog格式的结构化数据转换为格式化的输出?

我最近一直在Serilog中使用结构化数据结构,尽管它的优点是紧凑的大型数据结构(5个或更多属性)很难在不格式化的情况下在控制台/文件中读取。

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

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

由此:

{ "Fruit": ["Apple", "Pear", "Orange"] }
Run Code Online (Sandbox Code Playgroud)

对此:

{
  "Fruit": [
    "Apple",
    "Pear",
    "Orange"
  ]
}
Run Code Online (Sandbox Code Playgroud)

编辑: 目前,我正在使用,JsonConvert.SerializeObject({...}, Formatting.Indented)但由于诸如控制台包中的正确着色,更快的序列化,推迟的序列化等原因,我想摆脱这一点。

Chr*_*rre 3

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

如果您还没有的话,您可以看一下https://github.com/serilog/serilog/wiki/Formatting-Output

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

  • @janfrg 我和你有几乎同样的问题 - 你有没有解决这个问题? (2认同)