'How to add health checks to .Net core Background service

I am having a .net core 2.1 Background service application which is subscribed to a queue in Microsoft Azure Service bus. It has some logic and it calls to an api over http. I would like to create a health check for this service. Could anyone please help me out?



Solution 1:[1]

Official HealthCheck premiere was in 2.2:

https://devblogs.microsoft.com/aspnet/asp-net-core-2-2-0-preview1-healthcheck/

Health checks in ASP.NET Core 2.2:

https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/health-checks?view=aspnetcore-2.2

For 5.0:

https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/health-checks?view=aspnetcore-5.0

If you have to stay on 2.1 than I suggest to create a special endpoint for it.

Solution 2:[2]

This worked for me https://dzone.com/articles/monitoring-health-of-aspnet-core-background-servic

It refers to use TCP probes

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 velsorange
Solution 2 Daniel José Martínez Parra