private static LogConfig ReadLogConfig()
		{
			var logConfig = new LogConfig();
			if(!File.Exists(LogConfigPath))
				return logConfig;
			using(var sr = new StreamReader(LogConfigPath))
			{
				LogConfigItem current = null;
				string line;
				while(!sr.EndOfStream && (line = sr.ReadLine()) != null)
				{
					var match = NameRegex.Match(line);
					if(match.Success)
					{
						current = new LogConfigItem(match.Groups["value"].Value);
						logConfig.Items.Add(current);
						continue;
					}
					if(current == null)
						continue;
					if(TryParseLine(line, LogLevelRegex, ref current.LogLevel))
						continue;
					if(TryParseLine(line, FilePrintingRegex, ref current.FilePrinting))
						continue;
					if(TryParseLine(line, ConsolePrintingRegex, ref current.ConsolePrinting))
						continue;
					if(TryParseLine(line, ScreenPrintingRegex, ref current.ScreenPrinting))
						continue;
					var verbose = false;
					if(TryParseLine(line, VerboseRegex, ref verbose))
						current.Verbose = verbose;
				}
			}
			return logConfig;
		}
		private static void WriteLogConfig(LogConfig logConfig)
		{
			try
			{
				// ReSharper disable once ObjectCreationAsStatement
				if(File.Exists(LogConfigPath))
					new FileInfo(LogConfigPath) {IsReadOnly = false};
			}
			catch(Exception e)
			{
				Log.Error("Could not remove read-only from log.config:\n" + e);
			}
			Log.Info("Updating log.config");
			using(var sw = new StreamWriter(LogConfigPath))
				sw.Write(string.Concat(logConfig.Items));
		}
Пример #3
0
 private static void WriteLogConfig(LogConfig logConfig)
 {
     try
     {
         // ReSharper disable once ObjectCreationAsStatement
         if (File.Exists(LogConfigPath))
         {
             new FileInfo(LogConfigPath)
             {
                 IsReadOnly = false
             }
         }
         ;
     }
     catch (Exception e)
     {
         Log.Error("Could not remove read-only from log.config:\n" + e);
     }
     Log.Info("Updating log.config");
     using (var sw = new StreamWriter(LogConfigPath))
         sw.Write(string.Concat(logConfig.Items));
 }