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:
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, int maxLength = 1000,
LogLevel logLevel = LogLevel.Information) LogLevel logLevel = LogLevel.Information)
{ {
var curl = client.GenerateCurlInString( try
request, {
config var curl = client.GenerateCurlInString(
).Truncate(maxLength); request,
logger?.Log(logLevel, "{curl}", curl); 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>( public static void LogCurl<TCategoryName>(
@@ -33,14 +40,21 @@ public static class LogExtensions
int maxLength = 1000, int maxLength = 1000,
LogLevel logLevel = LogLevel.Information) LogLevel logLevel = LogLevel.Information)
{ {
var curl = client.GenerateCurlInString( try
method, {
uri, var curl = client.GenerateCurlInString(
headers, method,
content, uri,
config headers,
).Truncate(maxLength); content,
logger?.Log(logLevel, "{curl}", curl); 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>( public static void LogCurl<TCategoryName>(
@@ -54,14 +68,21 @@ public static class LogExtensions
int maxLength = 1000, int maxLength = 1000,
LogLevel logLevel = LogLevel.Information) LogLevel logLevel = LogLevel.Information)
{ {
var curl = client.GenerateCurlInString( try
method, {
uri, var curl = client.GenerateCurlInString(
headers, method,
content, uri,
config headers,
).Truncate(maxLength); content,
logger?.Log(logLevel, "{curl}", curl); 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> /// <summary>