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:
@@ -14,6 +14,8 @@ public static class LogExtensions
|
|||||||
Action<StringConfig>? config = null,
|
Action<StringConfig>? config = null,
|
||||||
int maxLength = 1000,
|
int maxLength = 1000,
|
||||||
LogLevel logLevel = LogLevel.Information)
|
LogLevel logLevel = LogLevel.Information)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
var curl = client.GenerateCurlInString(
|
var curl = client.GenerateCurlInString(
|
||||||
request,
|
request,
|
||||||
@@ -21,6 +23,11 @@ public static class LogExtensions
|
|||||||
).Truncate(maxLength);
|
).Truncate(maxLength);
|
||||||
logger?.Log(logLevel, "{curl}", curl);
|
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>(
|
||||||
this ILogger<TCategoryName> logger,
|
this ILogger<TCategoryName> logger,
|
||||||
@@ -32,6 +39,8 @@ public static class LogExtensions
|
|||||||
Action<StringConfig>? config = null,
|
Action<StringConfig>? config = null,
|
||||||
int maxLength = 1000,
|
int maxLength = 1000,
|
||||||
LogLevel logLevel = LogLevel.Information)
|
LogLevel logLevel = LogLevel.Information)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
var curl = client.GenerateCurlInString(
|
var curl = client.GenerateCurlInString(
|
||||||
method,
|
method,
|
||||||
@@ -42,6 +51,11 @@ public static class LogExtensions
|
|||||||
).Truncate(maxLength);
|
).Truncate(maxLength);
|
||||||
logger?.Log(logLevel, "{curl}", curl);
|
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>(
|
||||||
this ILogger<TCategoryName> logger,
|
this ILogger<TCategoryName> logger,
|
||||||
@@ -53,6 +67,8 @@ public static class LogExtensions
|
|||||||
Action<StringConfig>? config = null,
|
Action<StringConfig>? config = null,
|
||||||
int maxLength = 1000,
|
int maxLength = 1000,
|
||||||
LogLevel logLevel = LogLevel.Information)
|
LogLevel logLevel = LogLevel.Information)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
var curl = client.GenerateCurlInString(
|
var curl = client.GenerateCurlInString(
|
||||||
method,
|
method,
|
||||||
@@ -63,6 +79,11 @@ public static class LogExtensions
|
|||||||
).Truncate(maxLength);
|
).Truncate(maxLength);
|
||||||
logger?.Log(logLevel, "{curl}", curl);
|
logger?.Log(logLevel, "{curl}", curl);
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
logger.LogError(ex, "An unexpected error occurred while logging the HTTP request as cURL.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Truncates the string to the specified max length and appends a suffix if truncated.
|
/// Truncates the string to the specified max length and appends a suffix if truncated.
|
||||||
|
|||||||
Reference in New Issue
Block a user