ASP.NET Core 3.1-运行状况检查UI无法正常工作

时间:2020-05-24 02:54:55

标签: asp.net-core-3.1 health-check

我已经开发了带有自定义运行状况检查的ASP.NET Core 3.1 MVC应用程序。如下所示,它工作正常。

enter image description here

但是,UI始终为空,因为/ health-api始终返回空数组。 enter image description here

enter image description here

它在ASP.NET 3.1 Core应用程序中,该应用程序可以位于https://github.com/prawin2k/HealhCheckMVC/tree/master/HealhCheckMVC

.NET Core版本-3.1(MVC) 健康检查版本-最新 操作系统:Windows Server 2016 其他:Visual Studio 2019

1 个答案:

答案 0 :(得分:1)

就我而言,运行状况检查UI本身不会启动并导致.net core 3.1 Web API应用程序崩溃。

错误消息: 无法构造某些服务(验证服务描述符'ServiceType:HealthChecks.UI.Core.Notifications.IHealthCheckFailureNotifier寿命:范围内的实现类型:HealthChecks.UI.Core.Notifications.WebHookFailureNotifier'时出错:无法解析服务尝试激活“ HealthChecks.UI.Core.Notifications.WebHookFailureNotifier”时输入类型“ HealthChecks.UI.Core.Data.HealthChecksDb”。)

修复:添加任何UI storage provider。就我而言,我选择了 AddInMemoryStorage()

Startup.cs

public void ConfigureServices(IServiceCollection services)
{
    ...
    
    services.AddHealthChecks() 
        .AddDbContextCheck<PollDbContext>() //nuget: Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore
        .AddApplicationInsightsPublisher(); //nuget: AspNetCore.HealthChecks.Publisher.ApplicationInsights

    services.AddHealthChecksUI() //nuget: AspNetCore.HealthChecks.UI
        .AddInMemoryStorage(); //nuget: AspNetCore.HealthChecks.UI.InMemory.Storage
        
    ...
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    ...
    
    app.UseHealthChecks("/healthcheck", new HealthCheckOptions
    {
        Predicate = _ => true,
        ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse //nuget: AspNetCore.HealthChecks.UI.Client
    });
    
    //nuget: AspNetCore.HealthChecks.UI
    app.UseHealthChecksUI(options =>
    {
        options.UIPath = "/healthchecks-ui";
        options.ApiPath = "/health-ui-api";
    });
    ...
}

appsettings.json

"HealthChecks-UI": {
    "DisableMigrations": true,
    "HealthChecks": [
        {
            "Name": "PollManager",
            "Uri": "/healthcheck"
        }
    ],
    "Webhooks": [
        {
            "Name": "",
            "Uri": "",
            "Payload": "",
            "RestoredPayload": ""
        }
    ],
    "EvaluationTimeOnSeconds": 10,
    "MinimumSecondsBetweenFailureNotifications": 60,
    "MaximumExecutionHistoriesPerEndpoint": 15
}