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:
@@ -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>
|
||||||
|
|||||||
Reference in New Issue
Block a user