private void AddExistingLogEntries() { lock (this.logger.LogLock) { this.logger.SuspendWriter(); try { // Add all existing log entries ColoredLogGroup currentGroup = null; using (var reader = new StreamReader(new FileStream(this.logger.LogPath, FileMode.Open, FileAccess.Read))) { string line; while ((line = reader.ReadLine()) != null) { LogColor color = LogEntryClassificationUtilities.GetLineColor(line); // If we need to start a new group if (currentGroup == null || color != currentGroup.Color) { // Write out the last group (if it exists) if (currentGroup != null) { this.AddLogGroup(currentGroup); } // Start the new group currentGroup = new ColoredLogGroup(color); } // Add the entry currentGroup.Entries.Add(line); } } // Add any items in the last group if (currentGroup != null) { this.AddLogGroup(currentGroup); } } catch (Exception exception) { var errorLogGroup = new ColoredLogGroup(LogColor.Error); errorLogGroup.Entries.Add($"Could not load log file {this.logger.LogPath}" + Environment.NewLine + exception); this.AddLogGroup(errorLogGroup); } finally { this.logger.ResumeWriter(); } } }
public void LogWorker(string message, bool isError) { var logType = isError ? LogType.Error : LogType.Message; var entry = new LogEntry { LogType = logType, Source = LogSource.VidCoderWorker, Text = LogEntryClassificationUtilities.GetEntryPrefix(logType, LogSource.VidCoderWorker) + message }; this.AddEntry(entry); }
// Adds pending entries to the UI private void ProcessPendingEntries() { List <ColoredLogGroup> entryGroups; lock (this.pendingEntriesLock) { if (this.pendingEntries.Count == 0) { // If we are already at the bottom, scroll to the end, which will fire after the entries have been added to the UI. if (this.ScrolledToEnd()) { this.logTextBox.ScrollToEnd(); } this.workerRunning = false; return; } // copy some pending items to groups entryGroups = new List <ColoredLogGroup>(); ColoredLogGroup currentGroup = null; int currentLines = 0; while (this.pendingEntries.Count > 0 && entryGroups.Count < MaxRunsPerDispatch && currentLines < MaxLinesPerDispatch) { LogEntry entry = this.pendingEntries.Dequeue(); LogColor entryColor = LogEntryClassificationUtilities.GetEntryColor(entry); if (currentGroup == null || entryColor != currentGroup.Color) { currentGroup = new ColoredLogGroup(entryColor); entryGroups.Add(currentGroup); } currentGroup.Entries.Add(entry.Text); currentLines++; } } this.AddLogGroups(entryGroups); this.ProcessPendingEntries(); }