代码之家  ›  专栏  ›  技术社区  ›  lmcarreiro

ASP.NET Core-尝试使用运行状况检查时出错

  •  4
  • lmcarreiro  · 技术社区  · 7 年前

    我正在尝试使用.NETCore2.2健康检查。

    在里面 ConfigureServices 我注册了实现 Microsoft.Extensions.Diagnostics.HealthChecks.IHealthCheck

    但是当我执行 UseHealthChecks 内部的扩展方法 Configure

    public void Configure(IApplicationBuilder app)
    {
        app.UseHealthChecks("/hc"); // <-- Error in this line
        // ...
    

    System.InvalidOperationException: 试图激活“Microsoft.AspNetCore.Diagnostics.HealthChecks.HealthCheckService”时,无法解析“Microsoft.Extensions.Diagnostics.HealthChecks.HealthCheckService”类型的服务

    1 回复  |  直到 7 年前
        1
  •  17
  •   Henk Mollema    7 年前

    您必须通过配置运行状况检查基础结构服务 AddHealthChecks() 扩展方法。例如:

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddHealthChecks();
    }
    

    the documentation .

        2
  •  14
  •   hpsanampudi Slava Latun    5 年前

    在我的例子中,运行状况检查UI本身没有启动和崩溃.net core 3.1 web API应用程序。

    错误消息: 有些服务无法构建(验证服务描述符“ServiceType:HealthChecks.UI.Core.Notifications.IHealthCheckFailureNotifier生存期:作用域实现类型:HealthChecks.UI.Core.Notifications.WebHookFailureNotifier”时出错):尝试激活“HealthChecks.UI.Core.Data.HealthChecksDb”时无法解析类型“HealthChecks.UI.Core.Data.HealthChecksDb”的服务。)e、 通知。WebHookFailureNotifier')

    修理 :添加任何 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
        }