public async Task TestLogs() { var outputStream = new MemoryStream(); await using (var testExecution = StartTraceeProcess("LoggerRemoteTest")) { //TestRunner should account for start delay to make sure that the diagnostic pipe is available. using var loggerFactory = new LoggerFactory(new[] { new TestStreamingLoggerProvider(outputStream) }); var client = new DiagnosticsClient(testExecution.TestRunner.Pid); var logSettings = new EventLogsPipelineSettings { Duration = Timeout.InfiniteTimeSpan }; await using var pipeline = new EventLogsPipeline(client, logSettings, loggerFactory); await PipelineTestUtilities.ExecutePipelineWithDebugee(pipeline, testExecution); } outputStream.Position = 0L; Assert.True(outputStream.Length > 0, "No data written by logging process."); using var reader = new StreamReader(outputStream); string firstMessage = reader.ReadLine(); Assert.NotNull(firstMessage); LoggerTestResult result = JsonSerializer.Deserialize <LoggerTestResult>(firstMessage); Assert.Equal("Some warning message with 6", result.Message); Assert.Equal("LoggerRemoteTest", result.Category); Assert.Equal("Warning", result.LogLevel); Assert.Equal("0", result.EventId); Validate(result.Scopes, ("BoolValue", "true"), ("StringValue", "test"), ("IntValue", "5")); Validate(result.Arguments, ("arg", "6")); string secondMessage = reader.ReadLine(); Assert.NotNull(secondMessage); result = JsonSerializer.Deserialize <LoggerTestResult>(secondMessage); Assert.Equal("Another message", result.Message); Assert.Equal("LoggerRemoteTest", result.Category); Assert.Equal("Warning", result.LogLevel); Assert.Equal("0", result.EventId); Assert.Equal(0, result.Scopes.Count); //We are expecting only the original format Assert.Equal(1, result.Arguments.Count); }
private static void ValidateLoggerRemoteCategoryInformationMessage(StreamReader reader) { string message = reader.ReadLine(); Assert.NotNull(message); LoggerTestResult result = JsonSerializer.Deserialize <LoggerTestResult>(message); Assert.Equal("Some warning message with 6", result.Message); Assert.Equal(LoggerRemoteTestName, result.Category); Assert.Equal("Information", result.LogLevel); Assert.Equal(0, result.EventId); Assert.Equal(string.Empty, result.EventName); Validate(result.Scopes, ("BoolValue", "true"), ("StringValue", "test"), ("IntValue", "5")); Validate(result.Arguments, ("arg", "6")); }
private static void ValidateAppLoggerCategoryErrorMessage(StreamReader reader) { string message = reader.ReadLine(); Assert.NotNull(message); LoggerTestResult result = JsonSerializer.Deserialize <LoggerTestResult>(message); Assert.Equal("Error message.", result.Message); Assert.Equal(AppLoggerCategoryName, result.Category); Assert.Equal("Error", result.LogLevel); Assert.Equal(0, result.EventId); Assert.Equal(string.Empty, result.EventName); Assert.Equal(0, result.Scopes.Count); //We are expecting only the original format Assert.Equal(1, result.Arguments.Count); }
private static void ValidateLoggerRemoteCategoryWarningMessage(StreamReader reader) { string message = reader.ReadLine(); Assert.NotNull(message); LoggerTestResult result = JsonSerializer.Deserialize <LoggerTestResult>(message); Assert.Equal("Another message", result.Message); Assert.Equal(LoggerRemoteTestName, result.Category); Assert.Equal("Warning", result.LogLevel); Assert.Equal(7, result.EventId); Assert.Equal("AnotherEventId", result.EventName); Assert.Equal(0, result.Scopes.Count); //We are expecting only the original format Assert.Equal(1, result.Arguments.Count); }
public async Task TestDiagnosticsEventPipeProcessorLogs() { var outputStream = new MemoryStream(); await using (var testExecution = RemoteTestExecution.StartRemoteProcess("LoggerRemoteTest", _output)) { //TestRunner should account for start delay to make sure that the diagnostic pipe is available. var loggerFactory = new LoggerFactory(new[] { new StreamingLoggerProvider(outputStream, LogFormat.Json) }); DiagnosticsEventPipeProcessor diagnosticsEventPipeProcessor = new DiagnosticsEventPipeProcessor( PipeMode.Logs, loggerFactory, Enumerable.Empty <IMetricsLogger>()); var processingTask = diagnosticsEventPipeProcessor.Process(testExecution.TestRunner.Pid, TimeSpan.FromSeconds(10), CancellationToken.None); //Add a small delay to make sure diagnostic processor had a chance to initialize await Task.Delay(1000); //Send signal to proceed with event collection testExecution.Start(); await processingTask; await diagnosticsEventPipeProcessor.DisposeAsync(); loggerFactory.Dispose(); } outputStream.Position = 0L; Assert.True(outputStream.Length > 0, "No data written by logging process."); using var reader = new StreamReader(outputStream); string firstMessage = reader.ReadLine(); Assert.NotNull(firstMessage); LoggerTestResult result = JsonSerializer.Deserialize <LoggerTestResult>(firstMessage); Assert.Equal("Some warning message with 6", result.Message); Assert.Equal("LoggerRemoteTest", result.Category); Assert.Equal("Warning", result.LogLevel); Assert.Equal("0", result.EventId); Validate(result.Scopes, ("BoolValue", "true"), ("StringValue", "test"), ("IntValue", "5")); Validate(result.Arguments, ("arg", "6")); string secondMessage = reader.ReadLine(); Assert.NotNull(secondMessage); result = JsonSerializer.Deserialize <LoggerTestResult>(secondMessage); Assert.Equal("Another message", result.Message); Assert.Equal("LoggerRemoteTest", result.Category); Assert.Equal("Warning", result.LogLevel); Assert.Equal("0", result.EventId); Assert.Equal(0, result.Scopes.Count); //We are expecting only the original format Assert.Equal(1, result.Arguments.Count); }
public async Task TestDiagnosticsEventPipeProcessorLogs() { var outputStream = new MemoryStream(); using (var testExecution = RemoteTest.StartRemoteProcess(LoggerRemoteTest.EntryPoint, nameof(LoggerRemoteTest), _output)) { _output.WriteLine($"Started remote execution {testExecution.RemoteProcess.Process.ProcessName} {testExecution.RemoteProcess.Process.Id}"); //Add a small delay to make sure the remote process had a chance to start and create the diagnostic pipe. await Task.Delay(1000); var loggerFactory = new LoggerFactory(new[] { new StreamingLoggerProvider(outputStream) }); DiagnosticsEventPipeProcessor diagnosticsEventPipeProcessor = new DiagnosticsEventPipeProcessor( ContextConfiguration, PipeMode.Logs, loggerFactory, Enumerable.Empty <IMetricsLogger>()); var processingTask = diagnosticsEventPipeProcessor.Process(testExecution.RemoteProcess.Process.Id, TimeSpan.FromSeconds(10), CancellationToken.None); //Add a small delay to make sure diagnostic processor had a chance to initialize await Task.Delay(1000); testExecution.Start(); await processingTask; await diagnosticsEventPipeProcessor.DisposeAsync(); loggerFactory.Dispose(); } outputStream.Position = 0L; Assert.True(outputStream.Length > 0, "No data written by logging process."); using var reader = new StreamReader(outputStream); string firstMessage = reader.ReadLine(); Assert.NotNull(firstMessage); LoggerTestResult result = JsonSerializer.Deserialize <LoggerTestResult>(firstMessage); Assert.Equal("Some warning message with 6", result.Message); Assert.Equal(nameof(LoggerRemoteTest), result.Category); Assert.Equal("Warning", result.LogLevel); Assert.Equal("0", result.EventId); Validate(result.Scopes, ("BoolValue", "true"), ("StringValue", "test"), ("IntValue", "5")); Validate(result.Arguments, ("arg", "6")); string secondMessage = reader.ReadLine(); Assert.NotNull(secondMessage); result = JsonSerializer.Deserialize <LoggerTestResult>(secondMessage); Assert.Equal("Another message", result.Message); Assert.Equal(nameof(LoggerRemoteTest), result.Category); Assert.Equal("Warning", result.LogLevel); Assert.Equal("0", result.EventId); Assert.Equal(0, result.Scopes.Count); //We are expecting only the original format Assert.Equal(1, result.Arguments.Count); }