Standardized Health Checks for ASP.NET Core applications.
This library provides a set of opinionated defaults and extension methods to simplify the configuration of health checks in ASP.NET Core applications, following best practices for health endpoints.
- Standardized Endpoints: Automatically maps health checks to
/.well-known/healthz, including specialized paths forlive,ready, andstartup. - Custom Response Writer: Provides a structured JSON response writer by default.
- Easy Configuration: Extension methods for
WebApplicationBuilderandWebApplicationfor one-line setup.
Install the package via NuGet:
dotnet add package Escendit.AspNetCore.Diagnostics.HealthChecksIn your Program.cs, add the health check defaults:
var builder = WebApplication.CreateBuilder(args);
// Add health check defaults
builder.AddHealthCheckDefaults(checks =>
{
// Add checks with specific tags
checks.AddCheck<MyLiveCheck>("live", tags: ["live"]);
checks.AddCheck<MyReadyCheck>("ready", tags: ["ready"]);
checks.AddCheck<MyStartupCheck>("startup", tags: ["startup"]);
// Tags can be combined to include a check in multiple endpoints
checks.AddCheck<MyCombinedCheck>("combined", tags: ["live", "ready"]);
});Note
Tags can be combined for a single health check. For example, a check tagged with both live and ready will be executed by both the live and ready endpoints.
Map the standardized endpoints in the request pipeline:
var app = builder.Build();
// Use health check defaults
app.UseHealthCheckDefaults();
app.Run();By default, the following endpoints are mapped:
/.well-known/healthz: General health status (includes "self" check)./.well-known/healthz/ready: Checks tagged withready./.well-known/healthz/live: Checks tagged withlive./.well-known/healthz/startup: Checks tagged withstartup.
Licensed under the Apache License 2.0.