【问题标题】:Application Insights Telemetry Client - How to show log entries in Azure Application InsightsApplication Insights Telemetry Client - 如何在 Azure Application Insights 中显示日志条目
【发布时间】: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


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2021-09-21
    • 1970-01-01
    • 1970-01-01
    • 2022-01-12
    • 2022-01-11
    • 1970-01-01
    • 1970-01-01
    • 2020-02-25
    • 1970-01-01
    相关资源
    最近更新 更多