PanoramicData.HealthChecks.Core 1.1.28

dotnet add package PanoramicData.HealthChecks.Core --version 1.1.28                
NuGet\Install-Package PanoramicData.HealthChecks.Core -Version 1.1.28                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PanoramicData.HealthChecks.Core" Version="1.1.28" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PanoramicData.HealthChecks.Core --version 1.1.28                
#r "nuget: PanoramicData.HealthChecks.Core, 1.1.28"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install PanoramicData.HealthChecks.Core as a Cake Addin
#addin nuget:?package=PanoramicData.HealthChecks.Core&version=1.1.28

// Install PanoramicData.HealthChecks.Core as a Cake Tool
#tool nuget:?package=PanoramicData.HealthChecks.Core&version=1.1.28                

PanoramicData.HealthChecks

Heath checks that support checking the versions of items in the deployed application.

Usage

All of the code to enable use of health checks goes in Program.cs (or Startup.cs on older systems).

Add the Nuget package

Add the PanoramicData.HealthChecks.Versions nuget package to the host application.

Enable the required healthchecks

Add the required health checks using the extension methods to the WebApplicationBuilder class:

builder.Services.AddVersionHealthCheck();
builder.Services.AddAssembliesHealthCheck();

Add only those healthchecks in whose results you are interested. Adding more than you need exposes potentially sensitive information unnecessarily, as well as bloating the JSON response sent for every request.

Enable authentication and authorization

Define an authorization scheme using a policy name to which we can refer later. Any form of authentication can be used as you prefer; we use Basic Authentication for this demo so that the demo is standalone.

const string HEALTHCHECKS_AUTHPOLICY = "HeathChecksPolicy";
builder.Services
    .AddHealthChecksBasicAuthentication(builder.Configuration, HEALTHCHECKS_AUTHPOLICY);

The AddHealthChecksBasicAuthentication extension method is part of the optional package PanoramicData.HealthChecks.BasicAuthentication. If you want to make use of this authentication method then you must additionally add this Nuget package to your solution, and supply security credentials in the secrets for the application. The structure of the secrets can be seen in userSecrets.example.json in the Demo project for using either a HashedPassword or Password.

Warning As always, remember to use a secure connection when using Basic Authentication so that sensitive information is not exposed in transit.

Next, we must ensure that authentication and authorization are enabled, so add them to the pipeline if they are not already part of it:

app.UseAuthentication();
app.UseAuthorization();

Define the healthchecks endpoint

Finally, define the healthcheck endpoint, specifying its URL and the authorization policy to be applied:

app.MapHealthChecks("_secureHealth", new() 
    { 
        ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse 
    })
    .RequireAuthorization(HEALTHCHECKS_AUTHPOLICY);

You can specify any authorization policy as part of the call to RequireAuthorization - there is no limitation to the type of the policy or the authentication scheme with which that policy is asssociated.

Note that we must specify a custom response writer in the MapHealthChecks method to enable output of custom data from the health checks. If no custom writer is defined then only the enum denoting the overall status of each healthcheck will be returned to the caller. It is this custom response writer that adds the custom data exposed by the health check to the caller.

Warning Enabling writing of custom data to the response risks exposing sensitive data captured by other health checks that are not in your control. Be sure to check the contents of responses each time you add a new healthcheck, to minimise the risk that sensitive information is exposed to callers to whom it is not appropriate.

Product Compatible and additional computed target framework versions.
.NET 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 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on PanoramicData.HealthChecks.Core:

Package Downloads
PanoramicData.HealthChecks.Versions

PanoramicData.HealthChecks.Versions

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.28 371 9/5/2023
1.1.22 185 7/21/2023
1.1.21 281 7/21/2023
1.1.19 129 7/21/2023
1.1.14 185 7/15/2023
1.1.12 152 7/14/2023
1.1.11 142 7/14/2023

Initial release