Publishing ASP.NET Core health check results to elmah.io

Since writing this post, we have launched elmah.io Heartbeats. ASP.NET Core Health Checks now integrates seamlessly with Heartbeats. Check out Logging heartbeats from ASP.NET Core for more information.

We just published a new integration between ASP.NET Core and elmah.io. As you already know, elmah.io comes with excellent support for ASP.NET Core. With the latest addition, integrating ASP.NET Core 2.2 health checks with elmah.io requires a few lines of code only. If you are not already familiar with health checks, I recommend you to read our guide ASP.NET Core 2.2 Health Checks Explained.

Back already? This means that you are now a true health checks expert and ready for the awesomeness to come. Health checks enables a much better approach to verify that your websites are working, compared to pinging the front page every 5 minutes. But, before putting health checks into production, you want to be able to monitor when your website starts complaining. elmah.io to the rescue!

To start monitoring your health check results, install the Elmah.Io.AspNetCore.HealthChecks NuGet package:

Install-Package Elmah.Io.AspNetCore.HealthChecks -IncludePrerelease

If you haven't already, enable health checks in your Startup.cs file:

public void ConfigureServices(IServiceCollection services)
{
    ...
    services
        .AddHealthChecks()
        .AddElmahIoPublisher("API_KEY", new Guid("LOG_ID"));
    ...
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    ...
    app.UseHealthChecks("/health");
    ...
}

Notice the call to the AddElmahIoPublisher-method, which is where the magic happens really. You probably also want to add custom checks using the AddCheck-method (as described in the guide), but I've excluded this for now.

Elmah.Io.AspNetCore.HealthChecks automatically picks up failing health checks and publish them to the log specified in the LOG_ID parameter. Your existing email subscriptions and apps will notify you when your website doesn't work as intended. The new package also works perfectly with an uptime monitoring service like Pingdom or elmah.io Uptime Monitoring.