Salix.AspNetCore.HealthCheck
1.1.0
dotnet add package Salix.AspNetCore.HealthCheck --version 1.1.0
NuGet\Install-Package Salix.AspNetCore.HealthCheck -Version 1.1.0
<PackageReference Include="Salix.AspNetCore.HealthCheck" Version="1.1.0" />
paket add Salix.AspNetCore.HealthCheck --version 1.1.0
#r "nuget: Salix.AspNetCore.HealthCheck, 1.1.0"
// Install Salix.AspNetCore.HealthCheck as a Cake Addin #addin nuget:?package=Salix.AspNetCore.HealthCheck&version=1.1.0 // Install Salix.AspNetCore.HealthCheck as a Cake Tool #tool nuget:?package=Salix.AspNetCore.HealthCheck&version=1.1.0
Salix.AspNetCore.HealthCheck
Package provides two functionalities for AspNet (Core) APIs:
- Custom formatter of health check results as JSON object (default response is plain-text)
- Page, displaying health check results in humanly readable format in colors.
JSON formatter
Returns all defined health checks as JSOn object with implemented details and error handling (exception details).
Example response:
{
"status": "Healthy",
"checks": [
{
"key": "Database",
"status": "Healthy",
"description": "Database is OK.",
"exception": null,
"data": [
{
"key": "ConnString",
"value": "Connection string (shown only in developer mode)"
}
]
},
{
"key": "ExtApi",
"status": "Healthy",
"description": "ExtAPI is OK.",
"exception": null,
"data": [
{
"key": "ExtApi URL",
"value": "https://extapi.com/api"
},
{
"key": "User",
"value": "username from config"
},
{
"key": "Password",
"value": "password from config"
},
{
"key": "Token",
"value": "Secret token from config"
}
]
}
]
}
Health check page
Controller action content compiler to issue HTML page with health check results:
Additional possibility to add some custom links to implemented functionalities for some sandbox or testing links (or anything else) to thi page.
NOTE: Does NOT bring entire MVC stack to display page.
Usage
Register your health checks normally as described in official Microsoft documentation:
builder.Services.AddHealthChecks()
.Add(new HealthCheckRegistration("Database", sp => new DummyDatabaseHealthCheck(builder.Environment.IsDevelopment()), HealthStatus.Unhealthy, null, TimeSpan.FromSeconds(10)))
.Add(new HealthCheckRegistration("ExtApi", sp => new DummyExternalApiHealthCheck(builder.Environment.IsDevelopment()), HealthStatus.Unhealthy, null, TimeSpan.FromSeconds(5)));
Then for WebApplication builder, use provided extension to use JSON fomatter:
app.UseJsonHealthChecks("/health", builder.Environment.IsDevelopment());
Health page
To add health page (humanized view of health check results), create or use existing controller and add action endpoint like in sample below:
[ApiController]
public class HealthCheckController : ControllerBase
{
private readonly HealthCheckService _healthChecks;
public HealthCheckController(HealthCheckService healthChecks) =>
_healthChecks = healthChecks;
[HttpGet("/healthpage")]
public async Task<ContentResult> ShowHealth()
{
var healthResult = await _healthChecks.CheckHealthAsync();
return new ContentResult
{
ContentType = "text/html",
StatusCode = (int)HttpStatusCode.OK,
Content = HealthTestPage.GetContents(
healthReport: healthResult,
originalHealthTestEndpoint: "/health",
testingLinks: new List<HealthTestPageLink>
{
new HealthTestPageLink { TestEndpoint = "/api/sample/exception", Name = "Exception", Description = "Throws dummy exception/error to check Json Error functionality." },
new HealthTestPageLink { TestEndpoint = "/api/sample/validation", Name = "Validation Error", Description = "Throws dummy data validation exception to check Json Error functionality for data validation." },
}),
};
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Multi-framework targetting.