-
-
Save smling/f00866e2d8337996f91ebb65d8edc220 to your computer and use it in GitHub Desktop.
Configure heath check endpoint with custom option.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | |
{ | |
app.UseHealthChecks("/health", new HealthCheckOptions | |
{ | |
ResponseWriter = async (context, report) => | |
{ | |
context.Response.ContentType = "application/json"; | |
HealthCheckResponse response = new HealthCheckResponse | |
{ | |
Status = report.Status.ToString(), | |
HealthCheckProbes = report.Entries.Select(o => new HealthCheckProbe | |
{ | |
Component = o.Key, | |
Description = o.Value.Description, | |
Status = o.Value.Status.ToString(), | |
Duration = o.Value.Duration, | |
Exception = o.Value.Exception == null ? string.Empty : o.Value.Exception.ToString(), | |
Message = o.Value.Exception == null ? string.Empty : o.Value.Exception.Message, | |
}), | |
Duration = report.TotalDuration, | |
}; | |
await context.Response.Body.WriteAsync(JsonSerializer.SerializeToUtf8Bytes(response)); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment