sha*_*aja 4 logging json serilog asp.net-core asp.net-core-webapi
我使用 Serilog 登录 Asp.net core Web api。我将其配置为使用 SQL 接收器,并且它使用 XML 形式的属性列数据在日志表中进行日志记录。
如何配置 Serilog 将属性列数据记录为 JSON 而不是 XML?
以下是我的 appsettings.json 文件内容。我安装了 Serilog.Formatting.Compact 包并在 appsettings.json 中添加了格式化程序设置。但 Properties 列数据仍然是 XML 格式。
"Serilog": {
    "MinimumLevel": "Information",
    "WriteTo": [
      {
        "Name": "MSSqlServer",
        "Args": {
          "connectionString": "",
          "formatter": "Serilog.Formatting.Compact.CompactJsonFormatter, Serilog.Formatting.Compact",
          "tableName": "Log"
        }
      }
    ]
  }
你的做法非常令人困惑,并且与其他一些库不相符。
首先是 MSSQLServerSink 配置的 Args 属性
"Args": {
    "tableName": "TestMvcClient",
    "schemaName": "dbo",
    "autoCreateSqlTable": true,
    "columnOptionsSection": {
        "addStandardColumns": [ "LogEvent" ], /* Use JSON Column LogEvent */
        "removeStandardColumns": [ "Properties" ], /* Remove XML Column Properties */
    }
}
您可以在 Serilog 源中找到它和 20 多个其他设置。
https://github.com/serilog/serilog-sinks-mssqlserver#custom-property-columns  
| 归档时间: | 
 | 
| 查看次数: | 2542 次 | 
| 最近记录: |