Pra*_*win 5 asp.net-core-3.1 health-check
我开发了一个带有自定义健康检查的 ASP.NET Core 3.1 MVC 应用程序。如下图所示,它工作得很好。
但是,UI 始终为空,因为 /health-api 始终返回空数组。

它位于 ASP.NET 3.1 Core 应用程序中,可以位于https://github.com/prawin2k/HealhCheckMVC/tree/master/HealhCheckMVC
.NET Core 版本 - 3.1 (MVC) Healthchecks 版本 - 最新操作系统:Windows Server 2016 其他:Visual Studio 2019
就我而言,运行状况检查 UI 本身不会启动和崩溃 .net core 3.1 Web API 应用程序。
错误消息: 无法构造某些服务(验证服务描述符“ServiceType:HealthChecks.UI.Core.Notifications.IHealthCheckFailureNotifier Lifetime:Scoped ImplementType:HealthChecks.UI.Core.Notifications.WebHookFailureNotifier”时出错:无法解析服务对于类型“HealthChecks.UI.Core.Data.HealthChecksDb”,同时尝试激活“HealthChecks.UI.Core.Notifications.WebHookFailureNotifier”。)
修复:添加任何UI 存储提供程序。就我而言,我选择了AddInMemoryStorage()
启动.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";
});
...
}
Run Code Online (Sandbox Code Playgroud)
应用程序设置.json
"HealthChecks-UI": {
"DisableMigrations": true,
"HealthChecks": [
{
"Name": "PollManager",
"Uri": "/healthcheck"
}
],
"Webhooks": [
{
"Name": "",
"Uri": "",
"Payload": "",
"RestoredPayload": ""
}
],
"EvaluationTimeOnSeconds": 10,
"MinimumSecondsBetweenFailureNotifications": 60,
"MaximumExecutionHistoriesPerEndpoint": 15
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11729 次 |
| 最近记录: |