.net6 健康检查
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews()
.Services
.AddHealthChecks(Configuration);
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
endpoints.MapHealthChecks("/health", new HealthCheckOptions
{
Predicate = r => r.Name.Contains("self")
});
});
}
static class ServiceCollectionExtensions
{
public static IServiceCollection AddHealthChecks(this IServiceCollection services, IConfiguration configuration)
{
services.AddHealthChecks()
.AddCheck("self", () => HealthCheckResult.Healthy());
//.AddUrlGroup(new Uri(configuration["IdentityUrlHC"]), name: "identityapi-check", tags: new string[] { "identityapi" });
return services;
}
}
直接请求链接:http://localhost:8888/health