public static async Task <HealthCheckResult> HealthCheck(this HealthCheckRegistration registration, IServiceProvider provider) { var context = new HealthCheckContext { Registration = registration }; var healthCheckResult = new HealthCheckResult(); try { var res = await registration.Factory(provider).CheckHealthAsync(context).ConfigureAwait(false); healthCheckResult = new HealthCheckResult() { Status = res.Status.ToHealthStatus(), Description = res.Description, Details = res.Data?.ToDictionary(i => i.Key, i => i.Value) }; if (res.Exception != null && !string.IsNullOrEmpty(res.Exception.Message)) { healthCheckResult.Details.Add("error", res.Exception.Message); } } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception e) { // Catch all exceptions so that a status can always be returned healthCheckResult.Details.Add("exception", e.Message); } #pragma warning restore CA1031 // Do not catch general exception types return(healthCheckResult); }
public static Microsoft.Extensions.Diagnostics.HealthChecks.HealthCheckResult ToHealthCheckResult(this HealthCheckResult result) { return(new Microsoft.Extensions.Diagnostics.HealthChecks.HealthCheckResult(result.Status.ToHealthStatus(), result.Description, null, result.Details)); }