From: Justin Anderson Date: Thu, 20 May 2021 02:29:06 +0000 (-0700) Subject: Fix propagation of event name through EventLogsPipeline (#2291) X-Git-Tag: submit/tizen/20210909.063632~15^2~16 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0794f8d6993c699c001582928520be3a44984370;p=platform%2Fcore%2Fdotnet%2Fdiagnostics.git Fix propagation of event name through EventLogsPipeline (#2291) * Fix Event ID and Name propagation in EventLogsPipeline and tests. Update logs pipeline tests to verify event name. --- diff --git a/src/Microsoft.Diagnostics.Monitoring.EventPipe/Logs/EventLogsPipeline.cs b/src/Microsoft.Diagnostics.Monitoring.EventPipe/Logs/EventLogsPipeline.cs index 7f512203f..56c2cefa3 100644 --- a/src/Microsoft.Diagnostics.Monitoring.EventPipe/Logs/EventLogsPipeline.cs +++ b/src/Microsoft.Diagnostics.Monitoring.EventPipe/Logs/EventLogsPipeline.cs @@ -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 { diff --git a/src/tests/EventPipeTracee/Program.cs b/src/tests/EventPipeTracee/Program.cs index ebc86212b..d4b469cea 100644 --- a/src/tests/EventPipeTracee/Program.cs +++ b/src/tests/EventPipeTracee/Program.cs @@ -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."); } } diff --git a/src/tests/Microsoft.Diagnostics.Monitoring.EventPipe/EventLogsPipelineUnitTests.cs b/src/tests/Microsoft.Diagnostics.Monitoring.EventPipe/EventLogsPipelineUnitTests.cs index b493d4d47..89741af17 100644 --- a/src/tests/Microsoft.Diagnostics.Monitoring.EventPipe/EventLogsPipelineUnitTests.cs +++ b/src/tests/Microsoft.Diagnostics.Monitoring.EventPipe/EventLogsPipelineUnitTests.cs @@ -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 Arguments { get; set; } public IDictionary Scopes { get; set; } diff --git a/src/tests/Microsoft.Diagnostics.Monitoring.EventPipe/TestStreamingLogger.cs b/src/tests/Microsoft.Diagnostics.Monitoring.EventPipe/TestStreamingLogger.cs index 151d28f42..c1075da38 100644 --- a/src/tests/Microsoft.Diagnostics.Monitoring.EventPipe/TestStreamingLogger.cs +++ b/src/tests/Microsoft.Diagnostics.Monitoring.EventPipe/TestStreamingLogger.cs @@ -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) {