Airbrake.ExceptionHandler.ParseBacktrace C# (CSharp) Method

ParseBacktrace() private method

Parses the back trace string from an exception into an XML document.
private ParseBacktrace ( XmlDocument doc, string stack ) : List
doc System.Xml.XmlDocument The document namespace context.
stack string The stack trace from the application.
return List
        private List<XmlElement> ParseBacktrace(XmlDocument doc, string stack)
        {
            List<XmlElement> backtrace = new List<XmlElement>();
            string[] lines = Regex.Split(stack, "\r\n");

            foreach (string line in lines)
            {
                XmlElement l = doc.CreateElement("line");

                string number = Regex.Match(line, @":line \d+").Value.Replace(":line", string.Empty);
                string file = Regex.Match(line, @"in (.*):").Value.Replace("in ", string.Empty).Replace(":", string.Empty);
                string method = Regex.Match(line, @"at .*\)").Value.Replace("at ", string.Empty);

                if (!string.IsNullOrEmpty(number))
                {
                    l.SetAttribute("number", number);
                }

                if (!string.IsNullOrEmpty(file))
                {
                    l.SetAttribute("file", file);
                }

                if (!string.IsNullOrEmpty(method))
                {
                    l.SetAttribute("method", method);
                }

                backtrace.Add(l);
            }

            return backtrace;
        }