Skip to content

Exception logging (ARCH1003)

Key dotnet.logging.exception-logging · Severity warning · Category logging

Logging only the message in a catch block loses the stack trace. Pass the exception object as the first argument.

catch (Exception ex)
{
_logger.LogError("Payment failed: {Message}", ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "Payment failed");
}

Add the exception object as the first parameter of the LogError call so the stack trace is preserved.