Add optional logging control to HandleResponseAsync
The HandleResponseAsync method was updated to include a new optional parameter, `logSuccess`, which allows control over whether successful HTTP responses are logged. The default value is `true`. This change applies to both `NETFRAMEWORK` and non-`NETFRAMEWORK` builds. The method's XML documentation was updated to reflect this new behavior.
This commit is contained in:
@@ -48,16 +48,17 @@ namespace ReC.Client
|
||||
|
||||
/// <summary>
|
||||
/// Logs the outcome of an HTTP response. Throws a <see cref="ReCApiException"/> when the
|
||||
/// response indicates a non-success status code; otherwise writes an informational log entry
|
||||
/// containing the request and response details.
|
||||
/// response indicates a non-success status code; otherwise (optionally) writes an informational
|
||||
/// log entry containing the request and response details.
|
||||
/// </summary>
|
||||
/// <param name="response">The HTTP response to inspect.</param>
|
||||
/// <param name="logger">An optional logger used to record the outcome. May be <see langword="null"/>.</param>
|
||||
/// <param name="logSuccess">When <see langword="false"/>, successful responses are not logged.</param>
|
||||
/// <param name="cancel">A token to cancel the operation.</param>
|
||||
#if NETFRAMEWORK
|
||||
public static async Task HandleResponseAsync(HttpResponseMessage response, ILogger logger = null, CancellationToken cancel = default)
|
||||
public static async Task HandleResponseAsync(HttpResponseMessage response, ILogger logger = null, bool logSuccess = true, CancellationToken cancel = default)
|
||||
#else
|
||||
public static async Task HandleResponseAsync(HttpResponseMessage response, ILogger? logger = null, CancellationToken cancel = default)
|
||||
public static async Task HandleResponseAsync(HttpResponseMessage response, ILogger? logger = null, bool logSuccess = true, CancellationToken cancel = default)
|
||||
#endif
|
||||
{
|
||||
var request = response.RequestMessage;
|
||||
@@ -66,6 +67,8 @@ namespace ReC.Client
|
||||
var statusCode = (int)response.StatusCode;
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
if (logSuccess)
|
||||
{
|
||||
logger?.LogInformation(
|
||||
"ReC API request succeeded. {Method} {Uri} -> {StatusCode} ({ReasonPhrase})",
|
||||
@@ -73,6 +76,7 @@ namespace ReC.Client
|
||||
uri,
|
||||
statusCode,
|
||||
response.ReasonPhrase);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user