From 46eccf7a9bbd3aecec0b49dae487b4e38bf9a3cb Mon Sep 17 00:00:00 2001 From: TekH Date: Wed, 20 May 2026 15:39:24 +0200 Subject: [PATCH] Validate logger presence for LogSuccessfulRequests Added a validation in the `ReCClient` constructor to ensure that an `ILogger` instance is provided when the `LogSuccessfulRequests` option in `ReCClientOptions` is enabled. Throws an `InvalidOperationException` with a detailed message if no logger is injected. The message includes guidance on resolving the issue by either registering a logging provider or disabling the option. --- src/ReC.Client/ReCClient.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/ReC.Client/ReCClient.cs b/src/ReC.Client/ReCClient.cs index f57d364..b67ae34 100644 --- a/src/ReC.Client/ReCClient.cs +++ b/src/ReC.Client/ReCClient.cs @@ -68,6 +68,13 @@ namespace ReC.Client { _http = httpClientFactory.CreateClient(ClientName); var opts = options?.Value ?? new ReCClientOptions(); + + if (opts.LogSuccessfulRequests && logger == null) + throw new InvalidOperationException( + $"{nameof(ReCClientOptions.LogSuccessfulRequests)} is enabled, but no {nameof(ILogger)} was injected into {nameof(ReCClient)}. " + + $"Register a logging provider (e.g. services.AddLogging()) so that an {nameof(ILogger)} can be resolved, " + + $"or set {nameof(ReCClientOptions.LogSuccessfulRequests)} to false."); + RecActions = new RecActionApi(_http, logger, opts); Results = new ResultApi(_http, logger, opts); Profiles = new ProfileApi(_http, logger, opts);