[.net core] Add healthcheck in .net core backend service

As previous mentioned on adding health check API in SpringBoot application. This article will introduce on adding basic health check in .net core application.Share Now

  1. Install health check library.
    In package management console, input command below.
    Install-Package Microsoft.Extensions.Diagnostics.HealthChecks
    view raw install.ps1 hosted with ❤ by GitHub
  2. Enable health check in application.
    In startup.cs`, find method ConfigureService()` add code below to enable health check.
    public void ConfigureServices(IServiceCollection services)
    {
    // Add heath check.
    services.AddHealthChecks();
    }
    view raw startup.cs hosted with ❤ by GitHub
  3. Add health check endpoint.
    In startup.cs method Configure(), add code below to add health check endpoint.
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
    // configure healthcheck endpoint.
    app.UseHealthChecks("/health");
    }
    view raw startup.cs hosted with ❤ by GitHub
  4. Test application.
    Run application in local computer and input endpoint /health, message will show as expected.
About C.H. Ling 260 Articles
a .net / Java developer from Hong Kong and currently located in United Kingdom. Thanks for Google because it solve many technical problems so I build this blog as return. Besides coding and trying advance technology, hiking and traveling is other favorite to me, so I will write down something what I see and what I feel during it. Happy reading!!!

1 Trackback / Pingback

  1. [.net core] custom health check probe - Ling's Note

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.