首页 > 解决方案 > Application Insights Telemetry Client - 如何在 Azure Application Insights 中显示日志条目

问题描述

我正在使用 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

标签: c#asp.net-coreazure-application-insights

解决方案


我添加了关闭此问题的帖子:

根据op提供的代码/配置,它们都是正确的。我也在我身边证实,它有效。

所以我猜这个问题可能是由于应用程序洞察摄取服务器的延迟。


推荐阅读