<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Untitled Publication]]></title><description><![CDATA[Untitled Publication]]></description><link>https://rahulpandey1589.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Mon, 31 Aug 2026 22:00:54 GMT</lastBuildDate><atom:link href="https://rahulpandey1589.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Health Check in Aspnet Core - Part  1]]></title><description><![CDATA[What are health checks and why it is important?
Health checks are one of the crucial features that every API should implement. It helps in monitoring different applications 24 * 7 and reduces the turnaround time in case of any failure.
In Aspnet Core...]]></description><link>https://rahulpandey1589.hashnode.dev/health-check-in-aspnet-core-part-1</link><guid isPermaLink="true">https://rahulpandey1589.hashnode.dev/health-check-in-aspnet-core-part-1</guid><category><![CDATA[asp.net core]]></category><category><![CDATA[health check]]></category><dc:creator><![CDATA[Rahul Pandey]]></dc:creator><pubDate>Sat, 22 Jul 2023 13:04:05 GMT</pubDate><content:encoded><![CDATA[<h3 id="heading-what-are-health-checks-and-why-it-is-important">What are health checks and why it is important?</h3>
<p>Health checks are one of the crucial features that every API should implement. It helps in monitoring different applications 24 * 7 and reduces the turnaround time in case of any failure.</p>
<p>In Aspnet Core, it is exposed by an application using an HTTP endpoint. Monitoring applications like <a target="_blank" href="https://newrelic.com/">New-Relic</a> or <a target="_blank" href="https://sentry.io">Sentry.io</a> can invoke these endpoints in regular intervals and raise necessary notifications in case of any failure.</p>
<p>Health checks can be used in the following scenarios.</p>
<ol>
<li><p>It can be used by Load Balancers to check the health of a particular application.</p>
</li>
<li><p>It can also provide a detailed description of disk usage or other physical server resources.</p>
</li>
<li><p>It can check the status of external endpoints as well.</p>
</li>
</ol>
<p>There are three different <code>HealthStatus</code> value</p>
<ul>
<li><p>Healthy</p>
</li>
<li><p>UnHealthy</p>
</li>
<li><p>Degraded</p>
</li>
</ul>
<p>This article is using .Net 6 Minimal Api. The complete source code could be found at <a target="_blank" href="https://github.com/rahulpandey1589/health-check.git">Health Check in Aspnet Core</a>, in the "Part-1" branch</p>
<ol>
<li><p>Download below mentioned Nuget packages</p>
<pre><code class="lang-plaintext"> dotnet add package Microsoft.Extensions.Diagnostics.HealthChecks
</code></pre>
</li>
<li><p>Open Program.cs file and configure health-check in it.</p>
<pre><code class="lang-csharp"> builder.Services.AddHealthChecks();
</code></pre>
</li>
<li><p>Once the configuration is done then we have to map the health check endpoint</p>
<pre><code class="lang-csharp"> app.MapHealthChecks(<span class="hljs-string">"/health-check"</span>);
</code></pre>
</li>
<li><p>The complete code is</p>
<pre><code class="lang-csharp"> <span class="hljs-keyword">var</span> builder = WebApplication.CreateBuilder(args);

 <span class="hljs-comment">// Add services to the container.</span>
 <span class="hljs-comment">// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle</span>
 builder.Services.AddEndpointsApiExplorer();
 builder.Services.AddSwaggerGen();

 builder.Services.AddHealthChecks();

 <span class="hljs-keyword">var</span> app = builder.Build();

 <span class="hljs-comment">// Configure the HTTP request pipeline.</span>
 <span class="hljs-keyword">if</span> (app.Environment.IsDevelopment())
 {
     app.UseSwagger();
     app.UseSwaggerUI();
 }

 app.UseHttpsRedirection();

 app.MapHealthChecks(<span class="hljs-string">"/health-check"</span>);

 app.Run();
</code></pre>
<p> Press F5 to run the application and navigate to /health-check endpoint. The following screen will be displayed.</p>
</li>
<li><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1690030071201/5eaa2d3c-600d-4b3c-bd17-8ba9c9e99c4e.png" alt class="image--center mx-auto" /></p>
</li>
</ol>
<p>This endpoint only displays the current status of the application whether it is <code>Healthy</code> or not. If there are some issues in the application, then it either display <code>Unhealthy</code> or <code>Degraded</code>. As you might be thinking this only provides a piece of basic information, but this feature can be used in other scenarios as well like checking database connection.</p>
<p>There are various NuGet packages available for different types of health check which we are going to cover in the next section.</p>
]]></content:encoded></item></channel></rss>