Пример #1
0
        public virtual void OnLog(LogEntry l)
        {
			// An exception, to have a clean, standard 'man' output without logging header.
			if (CommandLine.SystemEnvironment.Exists("help"))
			{
				Console.WriteLine(l.Message);
				return;
			}

			if (l.Type != LogType.Realtime)
			{
				string lines = l.GetStringLines().Trim();
				Console.WriteLine(lines);

				// File logging

				if (Storage != null)
				{
					lock (Storage)
					{
						if (Storage.GetBool("log.file.enabled"))
						{
							try
							{
								string logPath = Storage.Get("log.file.path").Trim();

								List<string> paths = ParseLogFilePath(logPath);
								foreach (string path in paths)
								{
									Directory.CreateDirectory(Path.GetDirectoryName(path));
									File.AppendAllText(path, lines + "\n");
								}
							}
							catch(Exception e) 
							{
								Log (LogType.Warning, Messages.Format("Log to file disabled due to error, {1}", e.Message));
								Storage.SetBool ("log.file.enabled", false);
							}
						}
					}
				}
			}
        }