Skip to content
This repository was archived by the owner on Dec 8, 2018. It is now read-only.

Commit 9722d89

Browse files
committed
Adjust log levels
1 parent 014e7eb commit 9722d89

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

src/Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions/HealthStatus.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ namespace Microsoft.Extensions.Diagnostics.HealthChecks
1212
/// and the corresponding value of <see cref="HealthCheckRegistration.FailureStatus"/>.
1313
/// </para>
1414
/// <para>
15+
/// A status of <see cref="Unhealthy"/> should be considered the default value for a failing health check. Application
16+
/// developers may configure a health check to report a different status as desired.
17+
/// </para>
18+
/// <para>
1519
/// The values of this enum or ordered from least healthy to most healthy. So <see cref="HealthStatus.Degraded"/> is
1620
/// greater than <see cref="HealthStatus.Unhealthy"/> but less than <see cref="HealthStatus.Healthy"/>.
1721
/// </para>

src/Microsoft.Extensions.Diagnostics.HealthChecks/DefaultHealthCheckService.cs

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,28 @@ public static class EventIds
154154
EventIds.HealthCheckBegin,
155155
"Running health check {HealthCheckName}");
156156

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>(
158161
LogLevel.Debug,
159162
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);
161179

162180
private static readonly Action<ILogger, string, double, Exception> _healthCheckError = LoggerMessage.Define<string, double>(
163181
LogLevel.Error,
@@ -181,7 +199,24 @@ public static void HealthCheckBegin(ILogger logger, HealthCheckRegistration regi
181199

182200
public static void HealthCheckEnd(ILogger logger, HealthCheckRegistration registration, HealthReportEntry entry, TimeSpan duration)
183201
{
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+
}
185220
}
186221

187222
public static void HealthCheckError(ILogger logger, HealthCheckRegistration registration, Exception exception, TimeSpan duration)

0 commit comments

Comments
 (0)