@@ -154,10 +154,28 @@ public static class EventIds
154
154
EventIds . HealthCheckBegin ,
155
155
"Running health check {HealthCheckName}" ) ;
156
156
157
- private static readonly Action < ILogger , string , double , HealthStatus , string , Exception > _healthCheckEnd = LoggerMessage . Define < string , double , HealthStatus , string > (
157
+ // These are separate so they can have different log levels
158
+ private static readonly string HealthCheckEndText = "Health check {HealthCheckName} completed after {ElapsedMilliseconds}ms with status {HealthStatus} and '{HealthCheckDescription}'" ;
159
+
160
+ private static readonly Action < ILogger , string , double , HealthStatus , string , Exception > _healthCheckEndHealthy = LoggerMessage . Define < string , double , HealthStatus , string > (
158
161
LogLevel . Debug ,
159
162
EventIds . HealthCheckEnd ,
160
- "Health check {HealthCheckName} completed after {ElapsedMilliseconds}ms with status {HealthStatus} and '{HealthCheckDescription}'" ) ;
163
+ HealthCheckEndText ) ;
164
+
165
+ private static readonly Action < ILogger , string , double , HealthStatus , string , Exception > _healthCheckEndDegraded = LoggerMessage . Define < string , double , HealthStatus , string > (
166
+ LogLevel . Warning ,
167
+ EventIds . HealthCheckEnd ,
168
+ HealthCheckEndText ) ;
169
+
170
+ private static readonly Action < ILogger , string , double , HealthStatus , string , Exception > _healthCheckEndUnhealthy = LoggerMessage . Define < string , double , HealthStatus , string > (
171
+ LogLevel . Error ,
172
+ EventIds . HealthCheckEnd ,
173
+ HealthCheckEndText ) ;
174
+
175
+ private static readonly Action < ILogger , string , double , HealthStatus , string , Exception > _healthCheckEndFailed = LoggerMessage . Define < string , double , HealthStatus , string > (
176
+ LogLevel . Error ,
177
+ EventIds . HealthCheckEnd ,
178
+ HealthCheckEndText ) ;
161
179
162
180
private static readonly Action < ILogger , string , double , Exception > _healthCheckError = LoggerMessage . Define < string , double > (
163
181
LogLevel . Error ,
@@ -181,7 +199,24 @@ public static void HealthCheckBegin(ILogger logger, HealthCheckRegistration regi
181
199
182
200
public static void HealthCheckEnd ( ILogger logger , HealthCheckRegistration registration , HealthReportEntry entry , TimeSpan duration )
183
201
{
184
- _healthCheckEnd ( logger , registration . Name , duration . TotalMilliseconds , entry . Status , entry . Description , null ) ;
202
+ switch ( entry . Status )
203
+ {
204
+ case HealthStatus . Healthy :
205
+ _healthCheckEndHealthy ( logger , registration . Name , duration . TotalMilliseconds , entry . Status , entry . Description , null ) ;
206
+ break ;
207
+
208
+ case HealthStatus . Degraded :
209
+ _healthCheckEndDegraded ( logger , registration . Name , duration . TotalMilliseconds , entry . Status , entry . Description , null ) ;
210
+ break ;
211
+
212
+ case HealthStatus . Unhealthy :
213
+ _healthCheckEndUnhealthy ( logger , registration . Name , duration . TotalMilliseconds , entry . Status , entry . Description , null ) ;
214
+ break ;
215
+
216
+ case HealthStatus . Failed :
217
+ _healthCheckEndFailed ( logger , registration . Name , duration . TotalMilliseconds , entry . Status , entry . Description , null ) ;
218
+ break ;
219
+ }
185
220
}
186
221
187
222
public static void HealthCheckError ( ILogger logger , HealthCheckRegistration registration , Exception exception , TimeSpan duration )
0 commit comments