ℹ️ Select 'Choose Exercise', or randomize 'Next Random Exercise' in selected language.

Choose Exercise:
Timer 00:00
WPM --
Score --
Acc --
Correct chars --

Guard asynchronous logging

Goal -- WPM

Ready
Exercise Algorithm Area
1public static class ApiLogger
2{
3public static void LogFailure(ILogger logger, string correlationId, Exception ex)
4{
5try
6{
7logger.LogError(ex, "API failure {CorrelationId}", correlationId);
8}
9catch
10{
11// swallow logging errors
12}
13}
14}
Algorithm description viewbox

Guard asynchronous logging

Algorithm description:

Log API failures without ever surfacing secondary exceptions while keeping the correlation id visible for tracing.

Algorithm explanation:

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.

Pseudocode:

function LogFailure(logger, correlationId, exception)
    try
        logger.LogError(exception, "API failure {CorrelationId}", correlationId)
    catch
        // ignore logging errors
    end
end