gpt4 book ai didi

json - 如何在 serilog SQL 接收器中将属性数据记录为 JSON 而不是 XML

转载 作者:行者123 更新时间:2023-12-04 16:03:43 25 4
gpt4 key购买 nike

我使用 Serilog 登录 Asp.net 核心 web api。我将它配置为使用 SQL 接收器,它使用 Properties 列数据作为 XML 在日志表中进行记录。

如何配置 Serilog 以将 Properties 列数据记录为 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

关于json - 如何在 serilog SQL 接收器中将属性数据记录为 JSON 而不是 XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49696588/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com