·
Report Bug
·
Request Feature
Project allows you to have a HealthCheck that changes status based on if a Warning, Error or Critical event is logged.
In Startup.ConfigureServices
add
services.AddHealthChecks()
.AddLoggerHealthCheck();
This will add a healtcheck named Logs
that will have the status Degraded
if any Warning
s have been logged in the last 5 minutes, if any Error
s or Critical
s have been logged it will have the status Unhealthy
.
In Program.cs
add
.ConfigureLogging(builder => builder.AddHealthCheckLogger())
.UseSerilog((hostingContext, loggerConfiguration) => loggerConfiguration.ReadFrom.Configuration(hostingContext.Configuration), writeToProviders: true)
In Program.cs
add
.ConfigureLogging(builder => {
builder.AddHealthCheckLogger();
})
If you want to add a specific HealthCheck for one class you can use the .AddLoggerHealthCheckForType<T>()
method in Startup.ConfigureServices
this will scan for log entries that either have source set as T
, or where a Exception's stacktrace contains the type.
Filtration can be done at two diffrent levels
- At the Global level
When calling
AddHealthCheckLogger()
you can provide a HealthCheckLoggerProviderConfiguration instance, this allows you to specify a custom filtration, you should allways includeFilters.DefaultGlobalFilter
otherwise you might get a endless loop. - At HealthCheck level
When calling
AddLoggerHealthCheck()
you can provide a LoggerHealthCheckOptions instance, this allows you to specify a specific filter for that specific HealthCheck.
See HealthCheckLoggerProviderConfiguration
A example can be found in the LoggerHealthCheckExample and LoggerHealthCheckExampleWithSerilog directory.