Guard asynchronous logging
public static class ApiLogger { public static void LogFailure(ILogger logger, string correlationId, Exception ex) { try { logger.LogError(ex, "API failure {CorrelationId}", correlationId); } catch { // swallow logging errors } } }
Log API failures without ever surfacing secondary exceptions while keeping the correlation id visible for tracing.
Wraps the logger call in a try/catch so partner monitoring services never crash the calling transaction, and it preserves the unique correlation id in the structured log message.
function LogFailure(logger, correlationId, exception) try logger.LogError(exception, "API failure {CorrelationId}", correlationId) catch // ignore logging errors end end
Write a method that logs API failures with correlation ids, ensuring logging never throws.