我正在尝试使用 https://github.com/serilog/serilog-settings-configuration阅读应用程序设置和设置 serilog 以获取应用程序见解:https://github.com/serilog/serilog-sinks-applicationinsights .我遇到的问题是我无法为 ApplicationInsightsEvents 调用设置最后一个参数,这是一个采用 LogEvent 并返回 ITelemetry 的函数。如何通过 appsettings.json 进行设置?
基本上,我想替换以下行: log.WriteTo.ApplicationInsightsEvents(instrumentationKey, level, CultureInfo.CurrentCulture, TelemetryConverter.ConvertLogEventsToEnerGovTelemetry);
在 appsettings.json 中有一行
谢谢。
最佳答案
将接收器配置添加到 appsettings.json
{
"Name": "ApplicationInsights",
"Args": {
"instrumentationKey": "<instrumentationKey>",
"telemetryConverter": "Serilog.Sinks.ApplicationInsights.Sinks.ApplicationInsights.TelemetryConverters.TraceTelemetryConverter, Serilog.Sinks.ApplicationInsights",
"outputTemplate": "[{Component}|{MachineName}|{ThreadId}] {Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] <{SourceContext}> {Message:lj}{NewLine}{Exception}"
}
}
和
"Serilog.Sinks.ApplicationInsights"
到“Serilog:Using”数组
关于configuration - 通过 appsettings.json 为 Application Insights 配置 Serilog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54239936/