如何使用 Asp.Net-Core HealthChecks 设置 Application Insights

Ram*_*nas 5 azure-application-insights asp.net-core-2.2

Asp.Net Core 发布了 2.2 版,并附带了 HealthChecks 功能。(阅读更多)。它的功能之一是将运行状况检查结果推送到 Azure Application Insights。但是我还没有找到如何在 Azure 门户中查看这些结果的方法。要发送结果,我使用以下扩展名:

        services.AddHealthChecks()
            .AddSqlServer("...")
            .AddApplicationInsightsPublisher();
Run Code Online (Sandbox Code Playgroud)

有没有办法在 Application Insights 中查看这些健康检查报告?

编辑 1:我从官方github docs 中获取了示例。

编辑 2:如果我转到 Azure 门户查询分析,我会看到以下结果:

查询requests:

在此处输入图片说明

查询 customEvents

在此处输入图片说明

这里:GET /health是我的 healthCheck 端点。通过查询requests日志,我可以查看运行状况检查是否失败,但我想查看有关每个运行状况检查的更多详细信息,而且我认为我不需要为此进行任何扩展,因此我不明白AddApplicationInsightsPublisher()实际执行的操作。

Nat*_*and 3

当前发布者 (HealthCheckPublisherHostedService) 的注册存在问题,该问题将在 aspnet core 3 中修复。当前的解决方法是手动正确注册该类:

services.AddHealthChecks()
        .AddApplicationInsightsPublisher();

// This is a hack to fix an issue with the AddApplicationInsightsPublisher() call above
services.TryAddEnumerable(ServiceDescriptor.Singleton(typeof(IHostedService), typeof(HealthCheckPublisherOptions).Assembly.GetType("Microsoft.Extensions.Diagnostics.HealthChecks.HealthCheckPublisherHostedService")));
Run Code Online (Sandbox Code Playgroud)

请参阅: https: //github.com/aspnet/Extensions/issues/639