private void openLogFileButton_Click(object sender, EventArgs e) { var pid = Process.GetCurrentProcess().Id; var filePath = Directory.GetFiles(_logPath, "*-{0}.log".FormatWith(pid)).FirstOrDefault(); if (!string.IsNullOrEmpty(filePath)) { using (TextDisplayDialog dialog = new TextDisplayDialog(LogFileReader.Read(filePath), filePath)) { dialog.ShowDialog(this); } } else { MessageBox.Show("Log file not found for this worker"); } }
public void TrackEventLogFileTest() { IWorkContext context = WorkContext.Empty; string tempFolder = Path.Combine(Path.GetTempPath(), "TelemetryTest"); Directory.CreateDirectory(tempFolder); string logFileName; using (var logWriter = new LogFileWriter(tempFolder).Open()) using (EventRouter router = new EventRouter(context).Register("test", (x, _) => logWriter.Write(x))) { logFileName = logWriter.LogFileName; TrackEventSource source = new TrackEventSource(router, "test"); source.Verbose(context, "first message"); } var readList = new List <EventData>(); using (var reader = new LogFileReader(logFileName).Open()) { while (true) { IEnumerable <EventData> readItems = reader.Read(100); readItems.Should().NotBeNull(); if (!readItems.Any()) { break; } readList.AddRange(readItems); } } readList.Count.Should().Be(1); EventData eventData = readList[0]; eventData.EventSourceName.Should().Be("test"); eventData.EventName.Should().Be("Verbose"); eventData.TelemetryLevel.Should().Be(TelemetryLevel.Verbose); eventData.Cv.Should().Be(context.Cv.ToString()); eventData.Tag.Should().Be(context.Tag.ToString()); }
public static void Main() { ILogReader logReader; // log storage number one logReader = new LogFileReader(); List <LogEntry> logEntryList1 = logReader.Read(); Assert.Equal(2, logEntryList1.Count); Assert.Contains("LogFileReader", logEntryList1[0].Message); // log storage number two logReader = new WindowsEventLogReader(); List <LogEntry> logEntryList2 = logReader.Read(); Assert.Single(logEntryList2); Assert.Contains("WindowsEventLogReader", logEntryList2[0].Message); TestRunner.Print(); }
private void LoadFiles(string[] files, bool loadFiltered) { m_bindingSource.RaiseListChangedEvents = false; m_dataTable.Rows.Clear(); foreach (string file in files) { string fileWithoutExtension = Path.GetFileNameWithoutExtension(file); List <LogMessage> messages = LogFileReader.Read(file); FilterFirstChanceExceptions(messages); foreach (LogMessage message in messages) { if (!loadFiltered || IsShown(message)) { AddRowToDataTable(message, fileWithoutExtension); } } } m_bindingSource.RaiseListChangedEvents = true; m_bindingSource.ResetBindings(false); RefreshFilters(); }
public void MultipleTrackEventLogFileWithManagementTest() { IWorkContext context = WorkContext.Empty; string tempFolder = Path.Combine(Path.GetTempPath(), "TelemetryTest"); Directory.CreateDirectory(tempFolder); string logFileName; using (EventRouter router = new EventRouter(context)) { IEventDataWriter writer = router.AddLogWriter(tempFolder); Verify.IsNotNull(nameof(writer), writer); logFileName = writer.LogFileName; TrackEventSource source = new TrackEventSource(router, "test"); Enumerable.Range(0, 100).Run(x => { source.Verbose(context, $"{x}_verbose message"); source.Info(context, $"{x}_info message"); source.Critical(context, $"{x}_critical message"); }); } var readList = new List <EventData>(); using (var reader = new LogFileReader(logFileName).Open()) { IEnumerable <EventData> readItems = reader.Read(500); readItems.Should().NotBeNull(); readItems.Any().Should().BeTrue(); readList.AddRange(readItems); } readList.Count.Should().Be(300); IEnumerator <EventData> dataEnumerable = readList.GetEnumerator(); Enumerable.Range(0, 100).Run(x => { EventData ev; dataEnumerable.MoveNext().Should().BeTrue(); ev = dataEnumerable.Current; ev.EventSourceName.Should().Be("test"); ev.EventName.Should().Be("Verbose"); ev.TelemetryLevel.Should().Be(TelemetryLevel.Verbose); ev.Cv.Should().Be(context.Cv.ToString()); ev.Tag.Should().Be(context.Tag.ToString()); ev.Message.Should().Be($"{x}_verbose message"); dataEnumerable.MoveNext().Should().BeTrue(); ev = dataEnumerable.Current; ev.EventSourceName.Should().Be("test"); ev.EventName.Should().Be("Info"); ev.TelemetryLevel.Should().Be(TelemetryLevel.Informational); ev.Cv.Should().Be(context.Cv.ToString()); ev.Tag.Should().Be(context.Tag.ToString()); ev.Message.Should().Be($"{x}_info message"); dataEnumerable.MoveNext().Should().BeTrue(); ev = dataEnumerable.Current; ev.EventSourceName.Should().Be("test"); ev.EventName.Should().Be("Critical"); ev.TelemetryLevel.Should().Be(TelemetryLevel.Critical); ev.Cv.Should().Be(context.Cv.ToString()); ev.Tag.Should().Be(context.Tag.ToString()); ev.Message.Should().Be($"{x}_critical message"); }); }
public void MultipleTrackEventLogFileTest() { IWorkContext context = WorkContext.Empty; string tempFolder = Path.Combine(Path.GetTempPath(), "TelemetryTest"); Directory.CreateDirectory(tempFolder); string logFileName; using (var logWriter = new LogFileWriter(tempFolder).Open()) { logFileName = logWriter.LogFileName; EventRouter router = new EventRouter(context) .Register("test", (x, _) => logWriter.Write(x)); TrackEventSource source = new TrackEventSource(router, "test"); Enumerable.Range(0, 100).Run(x => { source.Verbose(context, $"{x}_verbose message"); source.Info(context, $"{x}_info message"); source.Critical(context, $"{x}_critical message"); }); Thread.Sleep(TimeSpan.FromSeconds(1)); } var readList = new List <EventData>(); using (var reader = new LogFileReader(logFileName).Open()) { while (true) { IEnumerable <EventData> readItems = reader.Read(500); readItems.Should().NotBeNull(); if (!readItems.Any()) { break; } readList.AddRange(readItems); } } readList.Count.Should().Be(300); IEnumerator <EventData> dataEnumerable = readList.GetEnumerator(); Enumerable.Range(0, 100).Run(x => { EventData ev; dataEnumerable.MoveNext().Should().BeTrue(); ev = dataEnumerable.Current; ev.EventSourceName.Should().Be("test"); ev.EventName.Should().Be("Verbose"); ev.TelemetryLevel.Should().Be(TelemetryLevel.Verbose); ev.Cv.Should().Be(context.Cv.ToString()); ev.Tag.Should().Be(context.Tag.ToString()); ev.Message.Should().Be($"{x}_verbose message"); dataEnumerable.MoveNext().Should().BeTrue(); ev = dataEnumerable.Current; ev.EventSourceName.Should().Be("test"); ev.EventName.Should().Be("Info"); ev.TelemetryLevel.Should().Be(TelemetryLevel.Informational); ev.Cv.Should().Be(context.Cv.ToString()); ev.Tag.Should().Be(context.Tag.ToString()); ev.Message.Should().Be($"{x}_info message"); dataEnumerable.MoveNext().Should().BeTrue(); ev = dataEnumerable.Current; ev.EventSourceName.Should().Be("test"); ev.EventName.Should().Be("Critical"); ev.TelemetryLevel.Should().Be(TelemetryLevel.Critical); ev.Cv.Should().Be(context.Cv.ToString()); ev.Tag.Should().Be(context.Tag.ToString()); ev.Message.Should().Be($"{x}_critical message"); }); }