fix(LogExtensions): Fehlerbehandlung zu den LogCurl-Erweiterungsmethoden hinzufügen

Umschließt die LogCurl-Methoden mit try-catch-Blöcken, um zu verhindern, dass unerwartete
Ausnahmen die Anwendung beim Generieren oder Protokollieren von
cURL-Darstellungen von HTTP-Anfragen zum Absturz bringen. Fehler werden nun mit
logger.LogError protokolliert.
This commit is contained in:
tekh 2025-08-18 17:14:44 +02:00
parent 49c4960f05
commit 8b9f7b911d

View File

@ -15,11 +15,18 @@ public static class LogExtensions
int maxLength = 1000,
LogLevel logLevel = LogLevel.Information)
{
var curl = client.GenerateCurlInString(
request,
config
).Truncate(maxLength);
logger?.Log(logLevel, "{curl}", curl);
try
{
var curl = client.GenerateCurlInString(
request,
config
).Truncate(maxLength);
logger?.Log(logLevel, "{curl}", curl);
}
catch(Exception ex)
{
logger.LogError(ex, "An unexpected error occurred while logging the HTTP request as cURL.");
}
}
public static void LogCurl<TCategoryName>(
@ -33,14 +40,21 @@ public static class LogExtensions
int maxLength = 1000,
LogLevel logLevel = LogLevel.Information)
{
var curl = client.GenerateCurlInString(
method,
uri,
headers,
content,
config
).Truncate(maxLength);
logger?.Log(logLevel, "{curl}", curl);
try
{
var curl = client.GenerateCurlInString(
method,
uri,
headers,
content,
config
).Truncate(maxLength);
logger?.Log(logLevel, "{curl}", curl);
}
catch (Exception ex)
{
logger.LogError(ex, "An unexpected error occurred while logging the HTTP request as cURL.");
}
}
public static void LogCurl<TCategoryName>(
@ -54,14 +68,21 @@ public static class LogExtensions
int maxLength = 1000,
LogLevel logLevel = LogLevel.Information)
{
var curl = client.GenerateCurlInString(
method,
uri,
headers,
content,
config
).Truncate(maxLength);
logger?.Log(logLevel, "{curl}", curl);
try
{
var curl = client.GenerateCurlInString(
method,
uri,
headers,
content,
config
).Truncate(maxLength);
logger?.Log(logLevel, "{curl}", curl);
}
catch (Exception ex)
{
logger.LogError(ex, "An unexpected error occurred while logging the HTTP request as cURL.");
}
}
/// <summary>