有没有办法把Serilog格式的结构化数据变成格式化输出?
我最近一直在 Serilog 中使用结构化数据结构,尽管它具有紧凑的优势,但大型数据结构(5 个属性或更多)很难在控制台/文件中读取,除非稍后对其进行格式化。
假设我只会在开发人员上启用它。
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/在开发过程中查看结构化输出,我强烈推荐它。
关于c# - Serilog 结构化数据 pretty-print ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45312584/