public static string ToFormattedString(this System.Exception exception) { IEnumerable <string> messages = exception .GetAllExceptions() .Where(e => !System.String.IsNullOrWhiteSpace(e.Message)) .Select(exceptionPart => exceptionPart.Message.Trim() + "\r\n" + (exceptionPart.StackTrace != null ? exceptionPart.StackTrace.Trim() : "")); string flattened = System.String.Join("\r\n\r\n", messages); // <-- the separator here return(flattened); }