public static Stack Create(string stackTrace) { Stack stack = new Stack(); if (string.IsNullOrEmpty(stackTrace)) { return stack; } stack.Frames = new List<StackFrame>(); var regex = new Regex(StackFrame.AT + @"([^)]+\))(" + StackFrame.IN + @"([^:]+:[^:]+)" + StackFrame.LINE + @" (.*))?", RegexOptions.Compiled); foreach (string line in stackTrace.Split(new string[] { Environment.NewLine }, StringSplitOptions.None)) { // at Type.Method() in File.cs : line X string current = line; var stackFrame = new StackFrame(); Match match = regex.Match(line); if (match.Success) { stackFrame.FullyQualifiedLogicalName = match.Groups[1].Value; if (!string.IsNullOrEmpty(match.Groups[2].Value)) { string fileName = match.Groups[3].Value; int lineNumber = int.Parse(match.Groups[4].Value); stackFrame.Uri = new Uri(fileName); stackFrame.Line = lineNumber; } } stack.Frames.Add(stackFrame); } return stack; }
public static ExceptionData Create(Exception exception) { return(new ExceptionData { Kind = exception.GetType().Name, Message = exception.Message, InnerExceptions = GetInnerExceptions(exception), Stack = Stack.Create(exception.StackTrace) }); }