private XmlDocument GetXML(Exception ex, List<KeyValuePair<string, string>> customParams = null)
{
// Create the xml document and Notice element
XmlDocument doc = new XmlDocument();
XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
doc.AppendChild(dec);
XmlElement root = doc.CreateElement("notice");
root.SetAttribute("version", "2.3");
// API Key
XmlElement apikey = doc.CreateElement("api-key");
apikey.InnerText = this.Apikey;
root.AppendChild(apikey);
// Notifier information
XmlElement notifier = doc.CreateElement("notifier");
// Notifier name
XmlElement name = doc.CreateElement("name");
name.InnerText = "aTech Media .Net Airbrake Client";
notifier.AppendChild(name);
// Notifier version
XmlElement version = doc.CreateElement("version");
version.InnerText = Assembly.GetExecutingAssembly().GetName().Version.ToString();
notifier.AppendChild(version);
// Notifier url
XmlElement url = doc.CreateElement("url");
url.InnerText = "http://www.atechmedia.com";
notifier.AppendChild(url);
// Append the notifier
root.AppendChild(notifier);
// Error information
XmlElement error = doc.CreateElement("error");
// error class
XmlElement cls = doc.CreateElement("class");
cls.InnerText = ex.GetType().Name;
error.AppendChild(cls);
// error message
XmlElement message = doc.CreateElement("message");
message.InnerText = ex.Message;
error.AppendChild(message);
// error backtrace
XmlElement backtrace = doc.CreateElement("backtrace");
// Add backtrace lines
foreach (XmlElement line in this.ParseBacktrace(doc, ex.StackTrace))
{
backtrace.AppendChild(line);
}
error.AppendChild(backtrace);
// Append the error
root.AppendChild(error);
// Reuqest information
XmlElement request = doc.CreateElement("request");
// Request component
XmlElement component = doc.CreateElement("component");
component.InnerText = ex.Source;
request.AppendChild(component);
// Request action
XmlElement action = doc.CreateElement("action");
action.InnerText = ex.TargetSite.Name;
request.AppendChild(action);
// CGI data
XmlElement cgi = doc.CreateElement("cgi-data");
// CGI OS
XmlElement os = doc.CreateElement("var");
os.SetAttribute("key", "Operating System");
os.InnerText = System.Environment.OSVersion.VersionString;
cgi.AppendChild(os);
// CGI Bits
XmlElement bits = doc.CreateElement("var");
bits.SetAttribute("key", "Platform");
bits.InnerText = System.Environment.OSVersion.Platform.ToString();
cgi.AppendChild(bits);
Assembly entryAssembly = Assembly.GetEntryAssembly();
if (entryAssembly != null) {
// CGI App
XmlElement app = doc.CreateElement("var");
app.SetAttribute("key", "Application Version");
app.InnerText = entryAssembly.GetName().Version.ToString();
cgi.AppendChild(app);
// CGI App-plat
XmlElement plat = doc.CreateElement("var");
plat.SetAttribute("key", "Application Platform");
plat.InnerText = entryAssembly.GetName().ProcessorArchitecture.ToString();
cgi.AppendChild(plat);
}
if (customParams != null)
{
// Custom Params
foreach (KeyValuePair<string, string> param in customParams)
{
XmlElement p = doc.CreateElement("var");
p.SetAttribute("key", param.Key);
p.InnerText = param.Value;
cgi.AppendChild(p);
}
}
// Append the CGI and request
request.AppendChild(cgi);
root.AppendChild(request);
// Environment info
XmlElement env = doc.CreateElement("server-environment");
if (entryAssembly != null) {
// Project root
XmlElement proj = doc.CreateElement("project-root");
proj.InnerText = entryAssembly.Location;
env.AppendChild(proj);
}
// Environment
XmlElement envname = doc.CreateElement("environment-name");
envname.InnerText = this.Environment;
env.AppendChild(envname);
// Append the environment to the root and doc
root.AppendChild(env);
doc.AppendChild(root);
return doc;
}