Fix propagation of event name through EventLogsPipeline (#2291)
authorJustin Anderson <jander-msft@users.noreply.github.com>
Thu, 20 May 2021 02:29:06 +0000 (19:29 -0700)
committerGitHub <noreply@github.com>
Thu, 20 May 2021 02:29:06 +0000 (19:29 -0700)
* Fix Event ID and Name propagation in EventLogsPipeline and tests.
Update logs pipeline tests to verify event name.

src/Microsoft.Diagnostics.Monitoring.EventPipe/Logs/EventLogsPipeline.cs
src/tests/EventPipeTracee/Program.cs
src/tests/Microsoft.Diagnostics.Monitoring.EventPipe/EventLogsPipelineUnitTests.cs
src/tests/Microsoft.Diagnostics.Monitoring.EventPipe/TestStreamingLogger.cs

index 7f512203fbc37868ad8a9f5dc539beb527dac68e..56c2cefa3c1e8d209ebab30680906a2cc01581ca 100644 (file)
@@ -148,7 +148,7 @@ namespace Microsoft.Diagnostics.Monitoring.EventPipe
                         //We replicate LoggerExtensions.Log, but add an interface capability to the object
                         //CONSIDER FormattedLogValues maintains a cache of formatters. We are effectively duplicating this cache.
                         var logValues = new FormattedLogValues(traceEvent.TimeStamp, formatString, args);
-                        logger.Log(logLevel, eventId, logValues, exception, _messageFormatter);
+                        logger.Log(logLevel, new EventId(eventId, eventName), logValues, exception, _messageFormatter);
                     }
                     else
                     {
index ebc86212bbc6658913bf2fe3c019ccb0247fad73..d4b469cea929e00b59fa79797075f7add4de0f14 100644 (file)
@@ -73,10 +73,10 @@ namespace EventPipeTracee
                 customCategoryLogger.LogInformation("Some warning message with {arg}", 6);
             }
 
-            customCategoryLogger.LogWarning("Another message");
+            customCategoryLogger.LogWarning(new EventId(7, "AnotherEventId"), "Another message");
 
             appCategoryLogger.LogInformation("Information message.");
-            appCategoryLogger.LogWarning("Warning message.");
+            appCategoryLogger.LogWarning(new EventId(5, "WarningEventId"), "Warning message.");
             appCategoryLogger.LogError("Error message.");
         }
     }
index b493d4d47a570be0c7af54482e80fe83cd7fe06a..89741af175af9c896e1d450bfe0e7f995a850480 100644 (file)
@@ -228,7 +228,8 @@ namespace Microsoft.Diagnostics.Monitoring.EventPipe.UnitTests
             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(0, result.EventId);
+            Assert.Equal(string.Empty, result.EventName);
             Validate(result.Scopes, ("BoolValue", "true"), ("StringValue", "test"), ("IntValue", "5"));
             Validate(result.Arguments, ("arg", "6"));
         }
@@ -242,7 +243,8 @@ namespace Microsoft.Diagnostics.Monitoring.EventPipe.UnitTests
             Assert.Equal("Another message", result.Message);
             Assert.Equal(LoggerRemoteTestName, result.Category);
             Assert.Equal("Warning", result.LogLevel);
-            Assert.Equal("0", result.EventId);
+            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);
@@ -257,7 +259,8 @@ namespace Microsoft.Diagnostics.Monitoring.EventPipe.UnitTests
             Assert.Equal("Information message.", result.Message);
             Assert.Equal(AppLoggerCategoryName, result.Category);
             Assert.Equal("Information", result.LogLevel);
-            Assert.Equal("0", result.EventId);
+            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);
@@ -272,7 +275,8 @@ namespace Microsoft.Diagnostics.Monitoring.EventPipe.UnitTests
             Assert.Equal("Warning message.", result.Message);
             Assert.Equal(AppLoggerCategoryName, result.Category);
             Assert.Equal("Warning", result.LogLevel);
-            Assert.Equal("0", result.EventId);
+            Assert.Equal(5, result.EventId);
+            Assert.Equal("WarningEventId", result.EventName);
             Assert.Equal(0, result.Scopes.Count);
             //We are expecting only the original format
             Assert.Equal(1, result.Arguments.Count);
@@ -287,7 +291,8 @@ namespace Microsoft.Diagnostics.Monitoring.EventPipe.UnitTests
             Assert.Equal("Error message.", result.Message);
             Assert.Equal(AppLoggerCategoryName, result.Category);
             Assert.Equal("Error", result.LogLevel);
-            Assert.Equal("0", result.EventId);
+            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);
@@ -313,7 +318,8 @@ namespace Microsoft.Diagnostics.Monitoring.EventPipe.UnitTests
         {
             public string Category { get; set; }
             public string LogLevel { get; set; }
-            public string EventId { get; set; }
+            public int EventId { get; set; }
+            public string EventName { get; set; }
             public string Message { get; set; }
             public IDictionary<string, JsonElement> Arguments { get; set; }
             public IDictionary<string, JsonElement> Scopes { get; set; }
index 151d28f42b7aa180166e28567f3220b2db953e96..c1075da38fa45fb4ae883c392fcac6b0b469fc1f 100644 (file)
@@ -86,7 +86,8 @@ namespace Microsoft.Diagnostics.Monitoring.EventPipe.UnitTests
             {
                 jsonWriter.WriteStartObject();
                 jsonWriter.WriteString("LogLevel", logLevel.ToString());
-                jsonWriter.WriteString("EventId", eventId.ToString());
+                jsonWriter.WriteNumber("EventId", eventId.Id);
+                jsonWriter.WriteString("EventName", eventId.Name ?? string.Empty);
                 jsonWriter.WriteString("Category", _categoryName);
                 if (exception != null)
                 {