/// <summary>Deserializes to an instance of XmlLogFile.</summary> /// <param name="reader">TextReader instance.</param> /// <returns>XmlLogFile result.</returns> public XmlLogFile Deserialize(TextReader reader) { XmlLogFile o = (XmlLogFile)s.Deserialize(reader); reader.Close(); return(o); }
private string StringSerialize(XmlLogFile xmllogfile) { TextWriter w = WriterSerialize(xmllogfile); string xml = w.ToString(); w.Close(); return(xml.Trim()); }
private TextWriter WriterSerialize(XmlLogFile xmllogfile) { TextWriter w = new StringWriter(); this.s = new XmlSerializer(this.type); s.Serialize(w, xmllogfile); w.Flush(); return(w); }
/// <summary>Serializes to an XmlDocument.</summary> /// <param name="xmllogfile">XmlLogFile to serialize.</param> /// <returns>XmlDocument instance.</returns> public XmlDocument Serialize(XmlLogFile xmllogfile) { string xml = StringSerialize(xmllogfile); XmlDocument doc = new XmlDocument(); doc.PreserveWhitespace = true; doc.LoadXml(xml); doc = Clean(doc); return(doc); }
/// <summary>Gets all logs.</summary> /// <returns>Log collection.</returns> public override List <Log> GetLogs() { try { XmlLogFile xlf = null; if (File.Exists(filename)) { xlf = XmlLogFileSerializer.ReadFile(filename); return(xlf.Logs); } } catch { } return(new List <Log>()); }
/// <summary>Writes config data to config file.</summary> /// <param name="file">Config file name.</param> /// <param name="config">Config object.</param> /// <returns>Boolean success.</returns> public static bool WriteFile(string file, XmlLogFile config) { bool ok = false; XmlLogFileSerializer serializer = new XmlLogFileSerializer(); try { string xml = serializer.Serialize(config).OuterXml; using (StreamWriter writer = new StreamWriter(file, false)) { writer.Write(xml.Trim()); writer.Flush(); writer.Close(); } ok = true; } catch { } return(ok); }
/// <summary>List<Log> an entry.</summary> /// <param name="log">ILog instance.</param> protected override void DoLog(ILog log) { XmlLogFile xlf = null; if (File.Exists(filename)) { xlf = XmlLogFileSerializer.ReadFile(filename); } if (xlf == null) { xlf = new XmlLogFile(); } if (xlf.Logs == null) { xlf.Logs = new List <Log>(); } xlf.Logs.Add(log as Log); XmlLogFileSerializer.WriteFile(filename, xlf); }