I needed to add health check for my Web API in ASP.Net Core. It needs to have an endpoint where it can be pinged to check if my system is healthy.
ASP.Net Core has an in-built support for health checks. It can be enabled in the Startup class.
public void ConfigureServices(IServiceCollection services)
{
// .. Other service configurations
services.AddHealthChecks();
// .. Other service configurations
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// .. Other app configurations
app.UseHealthChecks("/healthcheck");
// .. Other app configurations
}
Run the application and navigate to the health check endpoint, you should see the following result