【发布时间】:2020-01-14 10:40:04
【问题描述】:
我正在使用 Microsoft.Extensions.Hosting.BackgroundService。在 ExecuteAsync 方法中,我开始遥测操作:
using (_telemetryClient.StartOperation<RequestTelemetry>("someOperationName"))
{ [service implementation goes here] }
在服务实现中,我使用 _logger.LogInformation。 而且我还在我的服务实现中调用了不同类的其他方法,这些方法也记录了信息。
这些条目不会显示在 Azure 中。
有没有办法在 Azure Application Insights(性能 -> 操作选项卡)中自动显示所有调用方法的日志条目?
应用设置:
"Logging": {
"ApplicationInsights": {
"LogLevel": {
"Default": "Information"
}
},
"LogLevel": {
"Default": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
},
"AllowedHosts": "*"
},
配置服务:
services.AddHostedService<Worker>();
services.AddApplicationInsightsTelemetryWorkerService();
检测密钥在 Azure 中设置。 我按照以下说明操作:https://docs.microsoft.com/en-us/azure/azure-monitor/app/worker-service#net-core-30-worker-service-application
【问题讨论】:
-
不确定你的意思。如果您使用ILogger 界面来记录信息,并且您希望它出现在可行的应用洞察中。另一方面,如果要跟踪方法调用,则必须手动进行。例如,使用
StartOperation,就像你已经做的那样。 -
问题是 Ilogger 日志没有显示在应用程序 insigths 中。
-
你是如何设置日志的,你能分享一些代码吗?也可能是日志级别设置不正确,因此信息消息可能不会发送到 App Insights。你在用
LogInformation吗? -
我现在已将代码添加到我的问题中。是的,我使用“LogInformation”
-
@Julida,很高兴它已解决。这可能是由于应用洞察摄取服务器的延迟。
标签: c# asp.net-core azure-application-insights