A dotnet library to provide a fluent healthcheck service.
License
—
Deps
8
Install Size
—
Vulns
✓ 0
Published
Jan 20, 2026
$ dotnet add package ALSI.HealthCheckALSI.HealthCheck is a lightweight, modular health check library for .NET applications. It provides a fluent, builder-based API to register health checks for external APIs, databases, and custom background services. The library includes a hosted background service that exposes a configurable HTTP endpoint to collate and report health check results. Out-of-the-box, it supports multiple response formats via context serializers (JSON, plain text, etc.) and is fully configurable using dependency injection and strongly typed options.
HostedHealthChecker) listens on an HTTP endpoint and collates health check results.IContextSerializer interface (e.g. JSON and plain text).IOptions<T> using the HealthCheckOptions record.Install the package via NuGet:
dotnet add package ALSI.HealthCheck
Alternatively, search for ALSI.HealthCheck in your NuGet Package Manager.
The health check endpoint is configured using the HealthCheckOptions record. By default, the configuration is:
"*" (binds to all network interfaces)8080"/health" (the base path for health checks)You can override these defaults via your configuration file (e.g., appsettings.json):
{
"HealthCheck": {
"Hostname": "localhost",
"Port": 8081,
"UrlPath": "/health"
}
}
And register them in your DI container:
builder.Services.Configure<HealthCheckOptions>(builder.Configuration.GetSection("HealthCheck"));
Use the extension methods provided by the library to register your health checks. For example, in your Program.cs:
using ALSI.HealthCheck;
using ALSI.HealthCheck.Context;
var builder = Host.CreateApplicationBuilder(args);
// Register your health checks using the fluent builder API.
builder.Services.AddHealthChecker(healthBuilder =>
healthBuilder
.AddCheck("Basic Flip Flop", ctx =>
Task.FromResult(/* some condition */ HealthStatus.Healthy))
.AddCheck("AlwaysHealthy", _ =>
Task.FromResult(HealthStatus.Healthy))
.AddMonitoredService<YourMonitoredService>()
.AddMonitoredDatabaseConnection(
"DatabaseCheck",
() => new YourDbConnection(), // Your connection factory
"SELECT 1;"
)
.AddMonitoredApiRoute(
"ApiCheck",
() => new HttpClient(),
"http://example.com/api/health",
httpMethod: HttpMethod.Get,
expectedStatusCode: HttpStatusCode.OK
)
);
// Register the hosted health checker using your preferred context serializer.
builder.Services.AddHostedService<HostedHealthChecker<JsonContextSerializer>>();
var host = builder.Build();
host.Run();
The HostedHealthChecker<TContextSerializer> is a background service that:
HealthCheckOptions).JsonContextSerializer or PlainContextSerializer).When a GET request is made to the health check URL (e.g., http://localhost:8081/health), the service runs the checks and returns a response similar to:
{
"Status": "Healthy",
"Since": "00:00:06.8265131",
"Results": {
"Basic Flip Flop": "Healthy",
"AlwaysHealthy": "Healthy",
"DatabaseCheck": "Healthy",
"ApiCheck": "Healthy"
}
}
The package includes implementations of IContextSerializer:
You can also implement your own serializer by implementing IContextSerializer if you require a custom output format.
ALSI.HealthCheck is designed to be extensible:
Func<HealthCheckContext, Task<HealthStatus>> and register them via the builder.HealthCheck.IContextSerializer interface to create a custom serialization strategy.After configuring your health checks and registering the hosted service, run your host application. The health check endpoint will be available at the URL formed by combining the Hostname, Port, and UrlPath (e.g., http://localhost:8081/health). You can query this endpoint using a web browser or tools like curl or Postman.
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! If you have suggestions or bug fixes, please submit a pull request or open an issue on GitHub.