Microsoft.Extensions.Diagnostics.HealthChecks.HealthCheckResult
public HealthCheckResult (Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus status, string description = null, Exception exception = null, System.Collections.Generic.IReadOnlyDictionary<string,object> data = null);
Parameters
status HealthStatus
A value indicating the status of the component that was checked.
description String
A human-readable description of the status of the component that was checked.
exception Exception
An Exception representing the exception that was thrown when checking for status (if any).
data IReadOnlyDictionary<String,Object>
Additional key-value pairs describing the health of the component.
不幸的是,反复试验显示,健康检查端点响应中未返回description
。
catch(Exception ex)
{
return new HealthCheckResult(status: HealthStatus.Unhealthy,
description: ex.Message,
exception: ex);
}
我认为该异常消息将在响应中返回并显示在浏览器中,但不是。
是否有未记录的机制来返回Degraded
Healthy
Unhealthy
等之外的其他信息?
HealthCheckResult
是.Net Core中的结构。在CheckHealthAsync
界面的方法IHealthCheck
的实现中,您可以返回状态以及自定义描述,如下所示-
if (response.StatusCode == HttpStatusCode.OK)
{
return HealthCheckResult.Healthy("connected successfully.");
}
OR
return HealthCheckResult.Unhealthy("Failed to connect.)