Use this chapter for the smallest reliable setup for a service that exposes health endpoints.

Choose the right package

Install a package

dotnet add package DotNetDiag.HealthChecks.SqlServer
dotnet add package DotNetDiag.HealthChecks.Redis

Preview and integration packages are published through GitHub Packages:

<add key="DotNetDiag GitHub Packages" value="https://nuget.pkg.github.com/DotNetDiag/index.json" />

Register checks

services
    .AddHealthChecks()
    .AddSqlServer(Configuration["ConnectionStrings:sql"])
    .AddRedis(Configuration["ConnectionStrings:redis"]);

Each builder extension also supports operational metadata such as a custom name, tags, a failure status, and a timeout.

services
    .AddHealthChecks()
    .AddSqlServer(
        connectionString: Configuration["ConnectionStrings:sql"],
        healthQuery: "SELECT 1;",
        name: "sql",
        failureStatus: HealthStatus.Degraded,
        tags: ["db", "sql", "ready"]);

Separate liveness and readiness

Keep liveness lightweight and reserve readiness for external dependencies.

services
    .AddHealthChecks()
    .AddCheck("self", () => HealthCheckResult.Healthy(), tags: ["live"])
    .AddSqlServer(
        connectionString: Configuration["ConnectionStrings:sql"],
        name: "sql",
        failureStatus: HealthStatus.Degraded,
        tags: ["ready"]);

app.MapHealthChecks("/health/live", new HealthCheckOptions
{
    Predicate = registration => registration.Tags.Contains("live")
});

app.MapHealthChecks("/health/ready", new HealthCheckOptions
{
    Predicate = registration => registration.Tags.Contains("ready")
});