Skip to content

AddDbContextCheck - adding messages indicating reason for failure #56359

Answered by engineering87
jwm01cg asked this question in Q&A
Discussion options

You must be logged in to vote

The purpose of AddDbContextCheck is to determine if the application can connect to the database. If the health check relies on exceptions, there’s a risk that transient issues could cause the check to report unhealthy, even if the issue is momentary and could be resolved with a retry.
Maybe you can implement a custom health check that does a more detailed check and captures any exceptions thrown. You can then log the exception details while ensuring the health check remains performant by returning a failed result without rethrowing the exception. For example:

services.AddHealthChecks().AddDbContextCheck<MyContext>(
    "MyContext",
    customTestQuery: async (context, cancellationToken) =>

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jwm01cg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants