dotnet / dotnet/aspnetcore

DbContextHealthCheck should properly log all failure exception by default

Open
#62,600 2 comments 0 reactions 0 assignees View on GitHub
area-healthchecks
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

The current default implementation of `DbContextHealthCheck` uses `dbContext.Database.CanConnectAsync(token)` to determine the health status of the DB. The implementation of `CanConnectAsync` swallows errors and only returns `true`/`false` based on if it was able to connect or not. This does not give adequate details when health checks fail.

### Describe the solution you'd like

Update the default implementation of `DbContextHealthCheck` to properly log and have the health result contain any exceptions thrown when attempting to connect to the DB. This could either be just using its own "SELECT 1" logic or changing the default implementation to call `ExistsAsync` instead, since `CanConnectAsync` is just a wrapper around `ExistsAsync` that swallows errors.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.