← Каталог
Справочник по ASP.NET — 3. Health Checks
Фрагмент из «Справочник по ASP.NET»: 3. Health Checks.
app.MapHealthChecks("/health", new HealthCheckOptions
{
ResponseWriter = async (ctx, report) =>
{
ctx.Response.ContentType = "application/json";
var result = new
{
status = report.Status.ToString(),
checks = report.Entries.Select(e => new
{
e.Key,
e.Value.Status.ToString(),
e.Value.Description,
duration = e.Value.Duration.TotalMilliseconds
})
};
await ctx.Response.WriteAsync(JsonSerializer.Serialize(result));
}
}); app.MapHealthChecks("/health", new HealthCheckOptions
{
ResponseWriter = async (ctx, report) =>
{
ctx.Response.ContentType = "application/json";
var result = new
{
status = report.Status.ToString(),
checks = report.Entries.Select(e => new
{
e.Key,
e.Value.Status.ToString(),
e.Value.Description,
duration = e.Value.Duration.TotalMilliseconds
})
};
await ctx.Response.WriteAsync(JsonSerializer.Serialize(result));
}
});