Last active
January 6, 2016 08:07
-
-
Save elizabeth-young/5670577 to your computer and use it in GitHub Desktop.
Logged Error - serializes an exception into a list of strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Serializable] | |
public class LoggedError | |
{ | |
public List<string> Errors { get; set; } | |
public string StackTrace { get; set; } | |
public LoggedError() { } | |
public LoggedError(Exception ex) | |
{ | |
InitErrorList(ex); | |
} | |
/// <summary> | |
/// Retrieves exception and all inner exception messages into a more usable list of strings | |
/// </summary> | |
private void InitErrorList(Exception ex) | |
{ | |
StackTrace = ex.StackTrace; | |
Errors = new List<string>(); | |
while (ex != null) | |
{ | |
Errors.Add(ex.Message); | |
ex = ex.InnerException; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment