Add logging support to ReCClient and related APIs
Updated the `ReCClient` constructor to include an optional `ILogger` parameter for logging API call outcomes. Added support for both .NET Framework and other frameworks by using non-generic and generic `ILogger` types, respectively. Updated API-related objects (`RecActionApi`, `ResultApi`, etc.) to accept and utilize the `ILogger` instance for enhanced logging functionality.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using ReC.Client.Api;
|
||||
@@ -56,16 +57,21 @@ namespace ReC.Client
|
||||
/// Initializes a new instance of the <see cref="ReCClient"/> class.
|
||||
/// </summary>
|
||||
/// <param name="httpClientFactory">The factory to create HttpClients.</param>
|
||||
public ReCClient(IHttpClientFactory httpClientFactory)
|
||||
/// <param name="logger">An optional logger used to record API call outcomes.</param>
|
||||
#if NETFRAMEWORK
|
||||
public ReCClient(IHttpClientFactory httpClientFactory, ILogger logger = null)
|
||||
#else
|
||||
public ReCClient(IHttpClientFactory httpClientFactory, ILogger<ReCClient>? logger = null)
|
||||
#endif
|
||||
{
|
||||
_http = httpClientFactory.CreateClient(ClientName);
|
||||
RecActions = new RecActionApi(_http);
|
||||
Results = new ResultApi(_http);
|
||||
Profiles = new ProfileApi(_http);
|
||||
EndpointAuth = new EndpointAuthApi(_http);
|
||||
EndpointParams = new EndpointParamsApi(_http);
|
||||
Endpoints = new EndpointsApi(_http);
|
||||
Common = new CommonApi(_http);
|
||||
RecActions = new RecActionApi(_http, logger);
|
||||
Results = new ResultApi(_http, logger);
|
||||
Profiles = new ProfileApi(_http, logger);
|
||||
EndpointAuth = new EndpointAuthApi(_http, logger);
|
||||
EndpointParams = new EndpointParamsApi(_http, logger);
|
||||
Endpoints = new EndpointsApi(_http, logger);
|
||||
Common = new CommonApi(_http, logger);
|
||||
}
|
||||
|
||||
#region Static
|
||||
|
||||
Reference in New Issue
Block a user