This repository contains a set of extension methods for adding health checks to your ASP.NET Core application. Health checks are essential for monitoring the health and status of various components and services in your application.
- Clone or download this repository to your local development environment.
- Include the
HealthCheckExtensions.cs
file in your ASP.NET Core project.
To set up a custom health check endpoint, add the following code in your Program.cs
:
app.UseCustomHealthCheckMapping();
This code maps a custom health check endpoint to the /health
route. It provides the following status codes:
- Healthy: 200 OK
- Degraded: 200 OK
- Unhealthy: 503 Service Unavailable
Add health checks for various components using the provided extension methods in your Program.cs
:
services.AddSqlDatabaseHealthChecks(
connectionString,
name: "sql-database", // optional
tags: new[] { "database" } // optional
);
services.AddMongoDatabaseHealthChecks(
connectionString,
tags: new[] { "database" } // optional
);
services.AddRedisHealthChecks(
connectionString,
name: "redis-cache", // optional
tags: new[] { "cache" } // optional
);
The /health
endpoint returns a JSON response with detailed status information for each registered health check:
{
"status": "Healthy",
"results": {
"mongodb": {
"status": "Healthy",
"description": "MongoDB health check",
"data": {}
},
"sql-database": {
"status": "Healthy",
"description": "SQL Server health check",
"data": {}
}
}
}
This project is licensed under the MIT License - see the LICENSE file for details.