diff --git a/src/Build/BackEnd/Components/Logging/LoggingService.cs b/src/Build/BackEnd/Components/Logging/LoggingService.cs index 8e6b9ef1c0e..dc8467773b0 100644 --- a/src/Build/BackEnd/Components/Logging/LoggingService.cs +++ b/src/Build/BackEnd/Components/Logging/LoggingService.cs @@ -1438,7 +1438,7 @@ private void RouteBuildEvent(object loggingEvent) { if (ShouldTreatWarningAsMessage(warningEvent)) { - loggingEvent = new BuildMessageEventArgs( + buildEventArgs = new BuildMessageEventArgs( warningEvent.Subcategory, warningEvent.Code, warningEvent.File, @@ -1458,7 +1458,7 @@ private void RouteBuildEvent(object loggingEvent) } else if (ShouldTreatWarningAsError(warningEvent)) { - loggingEvent = new BuildErrorEventArgs( + buildEventArgs = new BuildErrorEventArgs( warningEvent.Subcategory, warningEvent.Code, warningEvent.File, @@ -1477,13 +1477,13 @@ private void RouteBuildEvent(object loggingEvent) } } - if (loggingEvent is BuildErrorEventArgs errorEvent) + if (buildEventArgs is BuildErrorEventArgs errorEvent) { // Keep track of build submissions that have logged errors. If there is no build context, add BuildEventContext.InvalidSubmissionId. _buildSubmissionIdsThatHaveLoggedErrors.Add(errorEvent.BuildEventContext?.SubmissionId ?? BuildEventContext.InvalidSubmissionId); } - if (loggingEvent is ProjectFinishedEventArgs projectFinishedEvent && projectFinishedEvent.BuildEventContext != null) + if (buildEventArgs is ProjectFinishedEventArgs projectFinishedEvent && projectFinishedEvent.BuildEventContext != null) { int key = GetWarningsAsErrorOrMessageKey(projectFinishedEvent); _warningsAsErrorsByProject?.Remove(key); @@ -1491,12 +1491,18 @@ private void RouteBuildEvent(object loggingEvent) _warningsAsMessagesByProject?.Remove(key); } - if (loggingEvent is BuildEventArgs loggingEventBuildArgs) + if (loggingEvent is BuildEventArgs) { - RouteBuildEvent(loggingEventBuildArgs); + RouteBuildEvent(buildEventArgs); } else if (loggingEvent is KeyValuePair loggingEventKeyValuePair) { + if (loggingEventKeyValuePair.Value != buildEventArgs) + { + // buildEventArgs has been altered, lets use that new one + loggingEventKeyValuePair = new KeyValuePair(loggingEventKeyValuePair.Key, buildEventArgs); + } + RouteBuildEvent(loggingEventKeyValuePair); } }