Skip to content

Commit 7e2e90f

Browse files
committed
fix: use console logger for health check to surface HealthCheckFailed errors
NullLogger.Instance was silently discarding the HealthCheckFailed(uri, exception) Error-level log that ExecuteAsync emits on connection failures, TLS errors, and DNS failures. The ILogger parameter was added to 0.0.72.928 specifically to expose this diagnostic; use a minimal console LoggerFactory so operators can see why a health check failed. Prompt: Work on pull request #383 in funfair-tech/BuildBot.
1 parent 981276b commit 7e2e90f

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

src/BuildBot/Program.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using BuildBot.Helpers;
66
using Credfeto.Docker.HealthCheck.Http.Client;
77
using Microsoft.AspNetCore.Builder;
8-
using Microsoft.Extensions.Logging.Abstractions;
8+
using Microsoft.Extensions.Logging;
99

1010
namespace BuildBot;
1111

@@ -20,13 +20,18 @@ public static class Program
2020
)]
2121
public static async Task<int> Main(string[] args)
2222
{
23-
return HealthCheckClient.IsHealthCheck(args: args, out string? checkUrl)
24-
? await HealthCheckClient.ExecuteAsync(
23+
if (HealthCheckClient.IsHealthCheck(args: args, out string? checkUrl))
24+
{
25+
using ILoggerFactory loggerFactory = LoggerFactory.Create(static builder => builder.AddConsole());
26+
27+
return await HealthCheckClient.ExecuteAsync(
2528
targetUrl: checkUrl,
26-
logger: NullLogger.Instance,
29+
logger: loggerFactory.CreateLogger(nameof(Program)),
2730
cancellationToken: CancellationToken.None
28-
)
29-
: await RunServerAsync(args);
31+
);
32+
}
33+
34+
return await RunServerAsync(args);
3035
}
3136

3237
private static async ValueTask<int> RunServerAsync(string[] args)

0 commit comments

Comments
 (0)