Using Health Checks to Improve the Reliability of Your ASP.NET Applications



Using Health Checks to Improve the Reliability of Your ASP.NET Applications

Using Health Checks to Improve the Reliability of Your ASP.NET Applications

#coding #codingbootcamp #softwaredeveloper

Enter to win free tuition! Enter below!
https://startuphakk.com/start-now/?v=9bXvHtj2-4E

GitHub Repo: https://github.com/slthomason/StartupHakk/tree/main/36_ASPNET_Health_Checks

An ultra-fast, ultra-responsive application is great, but nothing is more frustrating than an application that won’t load. Configure ASP.NET health checks to make sure your application is up and running.

How to implement the health check feature in ASP.NET Core 7
The implementation is really simple. In this .NET version what you need to do is to add the health check service and create a URL to call it in the Program class.

This implementation only checks if the application instance is OK or not. The next topic shows how to create a custom Health Check to verify specific dependencies.

How to implement a custom health check feature in ASP.NET Core 7
For checking specific features, for example, a connection with some database, we can create a custom health check.

Any custom health check must implement the IHealthCheck interface. This interface contains a method called CheckHealthAsync, which will be called every time we invoke the Health Check endpoint. The code below shows how to create a custom Health Check.

This custom health check only verifies if a random number is multiplied by 2. If so, a Healthy status will be returned by the method, otherwise Unhealthy status will be returned.

Of course, only the ASP.Net Health Check feature will not save your life! Nowadays there are a lot of great monitoring tools to help you. Choose something that makes sense for your application and makes your day easier.