【发布时间】:2020-06-17 20:40:56
【问题描述】:
是否可以在 Azure 表存储中的 Serilog 表中添加一个新列,用于记录新的额外字段,例如 accountID 或 login Name?
我认为可以添加一个新列,但是可以像我为新添加的列所说的那样在 Serilog 中传递额外的字段?我如何在 Startup.cs 或 web.config 中定义它?谢谢
这是我在 web.config 中的配置:
<add key="serilog:using:AzureTableStorage" value="Serilog.Sinks.AzureTableStorage" />
<add key="serilog:write-to:AzureTableStorageWithProperties.connectionString" value="DefaultEndpointsProtocol=https;AccountName=MyAccountName;AccountKey=MyAccountKey;EndpointSuffix=core.windows.net" />
<add key="serilog:write-to:AzureTableStorage.formatter" value="Serilog.Formatting.Compact.CompactJsonFormatter, Serilog.Formatting.Compact" />
<add key="serilog:write-to:AzureTableStorageWithProperties.storageTableName" value="Serilog" />
startup.cs 配置:
Log.Logger = new LoggerConfiguration()
.ReadFrom.AppSettings()
.CreateLogger();
【问题讨论】:
-
@Jawad 我把我的启动配置,你能给我一些实际的例子吗?
-
我不想重复努力,see this thread 用额外的字段丰富你的 Logger。您将无法在 LoggerConfiguration 中执行此操作,因为加载它的帐户不是您最可能想要捕获的 UserID。您还可以自定义 BatchFormatter 以在将事件 json 发送到 AzureTableStorage 之前对其进行修改
-
@Erased 对你有用吗?
标签: c# asp.net-mvc azure-table-storage serilog serilog-exceptions