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
- Install health check library.
In package management console, input command below.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersInstall-Package Microsoft.Extensions.Diagnostics.HealthChecks - Enable health check in application.
Instartup.cs
`, find methodConfigureService()
` add code below to enable health check.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characterspublic void ConfigureServices(IServiceCollection services) { // Add heath check. services.AddHealthChecks(); } - Add health check endpoint.
Instartup.cs
methodConfigure()
, add code below to add health check endpoint.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characterspublic void Configure(IApplicationBuilder app, IWebHostEnvironment env) { // configure healthcheck endpoint. app.UseHealthChecks("/health"); } - Test application.
Run application in local computer and input endpoint/health
, message will show as expected.
Leave a Reply