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.
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user