Skip to content

Instantly share code, notes, and snippets.

@elizabeth-young
Last active January 6, 2016 08:07
Show Gist options
  • Save elizabeth-young/5670577 to your computer and use it in GitHub Desktop.
Save elizabeth-young/5670577 to your computer and use it in GitHub Desktop.
Logged Error - serializes an exception into a list of strings
[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