internal static class ExceptionExtensions
{
public static string MessageEx(this Exception ex)
{
StringBuilder errorMessageBuilder = new StringBuilder();
Exception exception = ex;
while (exception != null)
{
errorMessageBuilder.AppendLine(exception.Message);
exception = exception.InnerException;
}
return errorMessageBuilder.ToString();
}
}
- Published on
Exception Extension for Simple Logging
- Authors
- Name
- Craig Wardman
There is nothing more annoying than tracing an exception that only says "see inner exception for details".
For this reason, I have started to use this simple extension method which traverses the entire exception structure, concatenating the messages together: