dotnet-cqrs/docs/observability/health-checks/aspnetcore-integration.md

47 lines
1.1 KiB
Markdown

# ASP.NET Core Integration
Integrate event streaming health checks with ASP.NET Core.
## Quick Start
```csharp
builder.Services.AddHealthChecks()
.AddCheck<StreamHealthCheck>("event-streams")
.AddCheck<ConsumerHealthCheck>("consumers")
.AddCheck<ProjectionHealthCheck>("projections");
app.MapHealthChecks("/health");
app.MapHealthChecks("/health/ready", new HealthCheckOptions
{
Predicate = check => check.Tags.Contains("ready")
});
```
## Custom Response Writer
```csharp
app.MapHealthChecks("/health/detail", new HealthCheckOptions
{
ResponseWriter = async (context, report) =>
{
context.Response.ContentType = "application/json";
await context.Response.WriteAsJsonAsync(new
{
status = report.Status.ToString(),
duration = report.TotalDuration.TotalMilliseconds,
checks = report.Entries.Select(e => new
{
name = e.Key,
status = e.Value.Status.ToString(),
description = e.Value.Description,
data = e.Value.Data
})
});
}
});
```
## See Also
- [Health Checks Overview](README.md)