示例#1
0
文件: Logger.cs 项目: Runcy/VidCoder
		public Logger(ILogger parent, string baseFileName)
		{
			this.parent = parent;

			HandBrakeUtils.MessageLogged += this.OnMessageLogged;
			HandBrakeUtils.ErrorLogged += this.OnErrorLogged;

			string logFolder = Path.Combine(Utilities.AppFolder, "Logs");
			if (!Directory.Exists(logFolder))
			{
				Directory.CreateDirectory(logFolder);
			}

			string logFileNamePrefix;
			if (baseFileName != null)
			{
				logFileNamePrefix = baseFileName + " ";
			}
			else
			{
				logFileNamePrefix = string.Empty;
			}

			this.LogPath = Path.Combine(logFolder, logFileNamePrefix + DateTimeOffset.Now.ToString("yyyy-MM-dd HH.mm.ss") + ".txt");
			this.logFile = new StreamWriter(this.LogPath);

			var initialEntry = new LogEntry
			{
				LogType = LogType.Message,
				Source = LogSource.VidCoder,
				Text = "## VidCoder " + Utilities.CurrentVersion + " (" + Utilities.Architecture + ")"
			};

			this.AddEntry(initialEntry);
		}
示例#2
0
文件: Logger.cs 项目: Runcy/VidCoder
		public void Log(string message)
		{
			string prefix = string.IsNullOrEmpty(message) ? string.Empty : "# ";

			var entry = new LogEntry
			{
			    LogType = LogType.Message,
				Source = LogSource.VidCoder,
				Text = prefix + message
			};

			this.AddEntry(entry);
		}
示例#3
0
文件: Logger.cs 项目: Runcy/VidCoder
		private void OnErrorLogged(object sender, MessageLoggedEventArgs e)
		{
			var entry = new LogEntry
			{
				LogType = LogType.Error,
				Source = LogSource.HandBrake,
				Text = "ERROR: " + e.Message
			};

			// Parent will also get this message
			this.AddEntry(entry, logParent: false);
		}
示例#4
0
文件: Logger.cs 项目: Runcy/VidCoder
		public void AddEntry(LogEntry entry, bool logParent = true)
		{
			lock (this.disposeLock)
			{
				if (this.disposed)
				{
					return;
				}
			}

			lock (this.LogLock)
			{
				this.LogEntries.Add(entry);
			}

			if (this.EntryLogged != null)
			{
				this.EntryLogged(this, new EventArgs<LogEntry>(entry));
			}

			try
			{
				this.logFile.WriteLine(entry.Text);
				this.logFile.Flush();

				if (this.parent != null && logParent)
				{
					this.parent.AddEntry(entry);
				}
			}
			catch (ObjectDisposedException)
			{
			}
		}
示例#5
0
文件: Logger.cs 项目: Runcy/VidCoder
		public void LogWorker(string message, bool isError)
		{
			var entry = new LogEntry
			{
				LogType = isError ? LogType.Error : LogType.Message,
				Source = LogSource.VidCoderWorker,
				Text = "* " + message
			};

			this.AddEntry(entry);
		}
示例#6
0
文件: Logger.cs 项目: Runcy/VidCoder
		public void LogError(string message)
		{
			var entry = new LogEntry
			{
				LogType = LogType.Error,
				Source = LogSource.VidCoder,
				Text = "# " + message
			};

			this.AddEntry(entry);
		}
示例#7
0
		private void AddEntry(LogEntry entry)
		{
			var run = new Run(entry.Text);

			if (entry.LogType == LogType.Error)
			{
				run.Foreground = new SolidColorBrush(Colors.Red);
			}
			else if (entry.Source == LogSource.VidCoder)
			{
				run.Foreground = new SolidColorBrush(Colors.DarkBlue);
			}
			else if (entry.Source == LogSource.VidCoderWorker)
			{
				run.Foreground = new SolidColorBrush(Colors.DarkGreen);
			}

			this.logDocument.Blocks.Add(new Paragraph(run));
		}