ASP.NET - Health Checks Framework

The Health Checks framework in ASP.NET Core is used to monitor whether an application and its dependencies are working correctly. It exposes special endpoints that report the app’s health status, helping systems detect problems early and respond automatically.


Purpose of Health Checks
Health checks are mainly used by load balancers, container platforms and monitoring tools. They verify if the app can handle requests, connect to databases or reach external services. If a check fails, traffic can be stopped or the app can be restarted.


How Health Checks Work
Health checks run small validation logic registered by the developer. Each check returns a status such as Healthy, Degraded or Unhealthy. ASP.NET Core collects all results and exposes them through a single endpoint that reflects the overall health of the application.


Built-in Health Checks
ASP.NET Core provides ready-made checks for common dependencies like SQL Server, Redis and URLs. These checks test connectivity and basic functionality without requiring custom code. Developers can also combine multiple checks into one endpoint.


Custom Health Checks
When built-in checks are not enough, custom checks can be written. A custom check implements a simple interface and returns a health result based on application-specific logic. This is useful for checking business rules or internal services.


Why Health Checks Are Important
Health checks improve reliability and uptime. They allow systems to detect failures automatically instead of waiting for users to report issues. In modern cloud and microservice environments, they are essential for stable deployments.


Example

var builder = WebApplication.CreateBuilder(args);

// Register health checks
builder.Services.AddHealthChecks()
    .AddCheck("basic_check", () => HealthCheckResult.Healthy());

var app = builder.Build();

// Expose health endpoint
app.MapHealthChecks("/health");

app.MapGet("/", () => "App is running");
app.Run();

Result

  • Visiting /health returns Healthy

  • Monitoring tools can use this endpoint to verify app status