Beispiel #1
0
 /// <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>());
 }
Beispiel #2
0
        /// <summary>Reads config data from config file.</summary>
        /// <param name="file">Config file name.</param>
        /// <returns><see cref="XmlLogFile"/> instance.</returns>
        public static XmlLogFile ReadFile(string file)
        {
            XmlLogFileSerializer serializer = new XmlLogFileSerializer();

            try
            {
                string xml = string.Empty;
                using (StreamReader reader = new StreamReader(file))
                {
                    xml = reader.ReadToEnd();
                    reader.Close();
                }
                return(serializer.Deserialize(xml));
            }
            catch { }
            return(new XmlLogFile());
        }
Beispiel #3
0
        /// <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);
        }
Beispiel #4
0
        /// <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);
        }