HealthCheckResult如何返回其他信息作为响应?

问题描述 投票:0回答:1
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);
}

我认为该异常消息将在响应中返回并显示在浏览器中,但不是。

是否有未记录的机制来返回DegradedHealthyUnhealthy等之外的其他信息?

asp.net-core-webapi health-monitoring
1个回答
0
投票

HealthCheckResult是.Net Core中的结构。在CheckHealthAsync界面的方法IHealthCheck的实现中,您可以返回状态以及自定义描述,如下所示-

   if (response.StatusCode == HttpStatusCode.OK)
   {
          return HealthCheckResult.Healthy("connected successfully.");
   }

OR

return HealthCheckResult.Unhealthy("Failed to connect.)
© www.soinside.com 2019 - 2024. All rights reserved.