Sage.Extensibility.InstallLog.ToXml C# (CSharp) Method

ToXml() public method

public ToXml ( XmlDocument ownerDoc ) : XmlElement
ownerDoc XmlDocument
return XmlElement
        public XmlElement ToXml(XmlDocument ownerDoc)
        {
            XmlElement logElement = ownerDoc.CreateElement("install");
            logElement.SetAttribute("dateTime", DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.ffff"));
            logElement.SetAttribute("result", this.Result.ToString());

            XmlElement filesElement = logElement.AppendElement("files");
            foreach (InstallItem file in this.Items)
            {
                XmlElement fileElement = filesElement.AppendElement("file");
                fileElement.SetAttribute("path", file.Path);
                fileElement.SetAttribute("crc", file.CrcCode);
                fileElement.SetAttribute("state", file.State.ToString().ToLower());
            }

            if (this.Error != null)
            {
                XmlElement errorElement = logElement.AppendElement("exception");
                errorElement.SetAttribute("message", this.Error.RootMessage());
                errorElement.SetAttribute("type", this.Error.RootTypeName());
                errorElement.InnerText = this.Error.RootStackTrace();
            }

            return logElement;
        }

Usage Example

Example #1
0
        private void SaveLog(InstallLog installLog)
        {
            XmlDocument logDoc = new XmlDocument();
            if (File.Exists(this.InstallLogFile))
                logDoc.Load(this.InstallLogFile);
            else
                logDoc.LoadXml(string.Format("<plugin name='{0}'></plugin>", this.Name));

            logDoc.DocumentElement.AppendChild(installLog.ToXml(logDoc));
            logDoc.Save(this.InstallLogFile);
        }