-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigure.HealthChecks.cs
More file actions
37 lines (31 loc) · 1 KB
/
Configure.HealthChecks.cs
File metadata and controls
37 lines (31 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using Microsoft.Extensions.Diagnostics.HealthChecks;
[assembly: HostingStartup(typeof(MyApp.HealthChecks))]
namespace MyApp;
public class HealthChecks : IHostingStartup
{
public class HealthCheck : IHealthCheck
{
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken token = default)
{
// Perform health check logic here
return HealthCheckResult.Healthy();
}
}
public void Configure(IWebHostBuilder builder)
{
builder.ConfigureServices(services =>
{
services.AddHealthChecks()
.AddCheck<HealthCheck>("HealthCheck");
services.AddTransient<IStartupFilter, StartupFilter>();
});
}
public class StartupFilter : IStartupFilter
{
public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
=> app => {
app.UseHealthChecks("/up");
next(app);
};
}
}