protected internal virtual XmlElement ConvertToXml(Exception instance, XmlDocument ownerDocument, ProblemInfo problemInfo = null)
{
XmlElement exceptionElement = ownerDocument.CreateElement("exception");
exceptionElement.SetAttribute("type", instance.GetType().ToString());
exceptionElement.SetAttribute("message", instance.Message);
exceptionElement.SetAttribute("htmlDescription", instance.Message
.Replace("<", "<")
.Replace(">", ">")
.Replace("\t", "    ")
.Replace("\n", "<br/>"));
XmlElement straceNode = (XmlElement) exceptionElement.AppendChild(ownerDocument.CreateElement("stacktrace"));
string[] stackTrace = instance.StackTrace != null
? instance.StackTrace.Split(new[] { '\n' })
: new[] { string.Empty };
if (instance.GetType() == typeof(XmlException))
{
exceptionElement.SetAttribute("sourceuri", ((XmlException) instance).SourceUri);
exceptionElement.SetAttribute("linenumber", ((XmlException) instance).LineNumber.ToString());
exceptionElement.SetAttribute("lineposition", ((XmlException) instance).LinePosition.ToString());
}
foreach (string t in stackTrace)
{
XmlElement frameNode = (XmlElement) straceNode.AppendChild(ownerDocument.CreateElement("frame"));
Match match;
if ((match = Regex.Match(t, "^\\s*at (.*) in (.*):line (\\d+)[\\s\\r]*$")).Success)
{
frameNode.SetAttribute("text", match.Groups[1].Value);
frameNode.SetAttribute("file", match.Groups[2].Value);
frameNode.SetAttribute("line", match.Groups[3].Value);
}
else
{
frameNode.SetAttribute("text", Regex.Replace(t, "^\\s*at ", string.Empty));
}
}
if (problemInfo != null && problemInfo.InfoBlocks.Count != 0)
{
foreach (KeyValuePair<string, IDictionary<string, string>> infoBlock in problemInfo.InfoBlocks)
{
XmlElement blockElement = exceptionElement.AppendElement("infoblock");
blockElement.SetAttribute("name", infoBlock.Key);
foreach (string key in infoBlock.Value.Keys)
{
string value = infoBlock.Value[key];
XmlElement lineElement = blockElement.AppendElement("line");
if (key != value)
lineElement.SetAttribute("name", key);
lineElement.InnerText = value;
}
}
}
return exceptionElement;
}