Skip to content

AnderssonPeter/LoggerHealthCheck

Repository files navigation

Logo

LoggerHealthCheck



· Report Bug · Request Feature

NuGet version run unit tests Coverage Status GitHub license

Table of Contents

About The Project

Project allows you to have a HealthCheck that changes status based on if a Warning, Error or Critical event is logged.

Getting Started

In Startup.ConfigureServices add

services.AddHealthChecks()
        .AddLoggerHealthCheck();

This will add a healtcheck named Logs that will have the status Degraded if any Warnings have been logged in the last 5 minutes, if any Errors or Criticals have been logged it will have the status Unhealthy.

With Serilog

In Program.cs add

.ConfigureLogging(builder => builder.AddHealthCheckLogger())
.UseSerilog((hostingContext, loggerConfiguration) => loggerConfiguration.ReadFrom.Configuration(hostingContext.Configuration), writeToProviders: true)

Without Serilog

In Program.cs add

.ConfigureLogging(builder => {
    builder.AddHealthCheckLogger();
})

Customization

Healtcheck for specific class

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.

Custom filtration

Filtration can be done at two diffrent levels

  1. At the Global level When calling AddHealthCheckLogger() you can provide a HealthCheckLoggerProviderConfiguration instance, this allows you to specify a custom filtration, you should allways include Filters.DefaultGlobalFilter otherwise you might get a endless loop.
  2. At HealthCheck level When calling AddLoggerHealthCheck() you can provide a LoggerHealthCheckOptions instance, this allows you to specify a specific filter for that specific HealthCheck.

Configuration

Global (AddHealthCheckLogger)

See HealthCheckLoggerProviderConfiguration

HealthCheck specific (AddLoggerHealthCheck)

See LoggerHealthCheckOptions

Example

A example can be found in the LoggerHealthCheckExample and LoggerHealthCheckExampleWithSerilog directory.

About

Project allows you to have a HealthCheck that changes status based on if a Warning, Error or Critical event is logged.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages