/// <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, LoggerConfig config) { bool ok = false; LoggerConfigSerializer serializer = new LoggerConfigSerializer(); try { string xml = serializer.Serialize(config).OuterXml; using (StreamWriter writer = new StreamWriter(file, false)) { writer.Write(xml); writer.Flush(); writer.Close(); } ok = true; } catch (Exception ex) { string logfile = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetCallingAssembly().CodeBase.Replace("file:///", "")) + @"\LoggerSerializerErrors.log"; ILogger logger = new FileLogger(logfile); logger.Log(new Log(ex)); throw; } return(ok); }
private ILogger GetLogger() { ILogger logger = null; try { logger = LoggerConfigSerializer.ReadFile(config).Logger; } catch { } return(logger); }
/// <summary>Reads config data from config file.</summary> /// <param name="file">Config file name.</param> /// <returns>LoggerConfig instance.</returns> public static LoggerConfig ReadFile(string file) { LoggerConfigSerializer serializer = new LoggerConfigSerializer(); // try { string xml = string.Empty; using (StreamReader reader = new StreamReader(file)) { xml = reader.ReadToEnd(); reader.Close(); } return(serializer.Deserialize(xml)); // } catch (Exception ex) { // string logfile = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetCallingAssembly().CodeBase.Replace("file:///", "")) + @"\LoggerSerializerErrors.log"; // ILogger logger = new FileLogger(logfile); // logger.Log(new Log(ex)); // //throw; // } // return new LoggerConfig(); }