public XDocument ToXml() { var doc = new XDocument( new XElement("HttpRequestLog", new XAttribute("Date", DateTime.UtcNow.ToString("u")), new XElement("Url", Url), new XElement("Method", Method), new XElement("StatusCode", StatusCode), new XElement("ResponseText", new XCData(Text)) ) ); if (PostData != null) { doc.Root.Add(PostData.ToXElement("PostData")); } if (RequestHeaders != null) { doc.Root.Add(RequestHeaders.ToXElement("RequestHeaders")); } if (ResponseHeaders != null) { doc.Root.Add(ResponseHeaders.ToXElement("ResponseHeaders")); } return(doc); }