Logs an appropriate error message for the exception, unwrapping
System.AggregateException
and System.Reflection.TargetInvocationException exceptions and ignoring LoggedException.
- Namespace
- Statiq
.Common - Containing Type
- ILoggerExtensions
Syntax
public static Exception LogAndWrapException(this ILogger logger, Exception exception)
Remarks
When using in a catch block, you should throw the result of this method instead of the original
exception to ensure the exception is wrapped in a
LoggedException as it bubbles up
and won't get logged again.
Parameters
| Name | Type | Description |
|---|---|---|
| logger | ILogger | The logger to log to. |
| exception | Exception | The exception to log. |
Return Value
| Type | Description |
|---|---|
| Exception | The original exception or a LoggedException wrapping the original exception. |