我开发了一个带有自定义健康检查的ASP.NET Core3.1MVC应用程序。它运行得很好,如下所示。

但是,UI始终是空的,因为/health总是返回空数组。


它在ASP.NET 3.1核心应用程序中,可以定位于https://github.com/prawin2k/HealhCheckMVC/tree/master/HealhCheckMVC
.NET核心版本- 3.1 (MVC)健康检查版本-最新操作系统:WindowsServer2016其他:VisualStudio2019
发布于 2020-07-24 15:30:14
在我的例子中,健康检查UI本身没有启动和破坏.net核心3.1WebAPI应用程序。
错误消息:某些服务无法构造(在验证服务描述符‘HealthChecks.UI.Core.Notifications.IHealthCheckFailureNotifier生命周期:作用域ImplementationType: HealthChecks.UI.Core.Notifications.WebHookFailureNotifier':无法解析服务类型'HealthChecks.UI.Core.Data.HealthChecksDb’时出错时出现错误,同时试图激活'HealthChecks.UI.Core.Notifications.WebHookFailureNotifier'.)
Fix:添加任何UI存储提供程序。在我的例子中我选择了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
}https://stackoverflow.com/questions/61981081
复制相似问题