c# - Serilog 结构化数据 pretty-print ?

标签 c# logging asp.net-core .net-core serilog

有没有办法把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/

相关文章:

c# - 选择行后调用哪个 DataGridView 事件

file - 如何将 stdout 和 stderr 重定向到文件并仍然仅输出 stderr?

python - 在 python 中打开调试日志记录

c# - 在 ASP.NET Core 中设置策略时,JWT 身份验证返回 401

asp.net-core - 如何使用 ReSharper 为 DNX 项目运行 xUnit 2.1.0-beta-*

c# - 停止由 CancellationToken 生成的异常被 ApplicationInsights 报告

c# - 添加 AsParallel() 调用导致我的代码在写入文件时中断

c# - iTextSharp - 填充动态表字段

c# - Datagrid 行样式绑定(bind)到动态更改的属性

python - 如何在 python 中禁用堆栈跟踪