ToXml() public method

Gets an XmlElement that contains information about this context.
/// is null. ///
public ToXml ( XmlDocument ownerDocument ) : XmlElement
ownerDocument System.Xml.XmlDocument The to use to create the element.
return System.Xml.XmlElement
Exemplo n.º 1
0
        /// <summary>
        /// Renders the exception to the specified <paramref name="writer"/>
        /// </summary>
        /// <param name="writer">The writer to render the exception to.</param>
        /// <param name="context">The context under which this code is executing.</param>
        public virtual void Render(TextWriter writer, SageContext context)
        {
            Contract.Requires<ArgumentNullException>(context != null);
            Contract.Requires<ArgumentNullException>(writer != null);

            XmlDocument document = new XmlDocument();
            XmlElement documentElement = document.AppendElement(this.ConvertToXml(this.Exception, document));
            Exception inner = this.Exception.InnerException;

            while (inner != null)
            {
                documentElement.AppendChild(this.ConvertToXml(inner, document));
                inner = inner.InnerException;
            }

            documentElement.AppendChild(context.ToXml(document));
            documentElement.SetAttribute("date", DateTime.Now.ToString("dd-MM-yyyy"));
            documentElement.SetAttribute("time", DateTime.Now.ToString("hh:mm:ss"));

            XsltTransform processor = XsltTransform.Create(context, this.StylesheetPath);
            XmlWriter xmlwr = XmlWriter.Create(writer, processor.OutputSettings);

            processor.Transform(documentElement, xmlwr, context, this.GetTransformArguments(context));
        }