From c11a7635bc23b4433c36229f2a6a7af56925ca27 Mon Sep 17 00:00:00 2001 From: YuliiaKovalova Date: Wed, 13 Aug 2025 13:34:04 +0200 Subject: [PATCH 1/4] remove SerialConsoleLogger --- src/Build.UnitTests/BinaryLogger_Tests.cs | 15 +- src/Build.UnitTests/ConsoleLogger_Tests.cs | 257 +---- src/Build/Logging/ConsoleLogger.cs | 39 +- .../ParallelLogger/ParallelConsoleLogger.cs | 1 + src/Build/Logging/SerialConsoleLogger.cs | 981 ------------------ src/Build/Microsoft.Build.csproj | 1 - src/MSBuild/Resources/Strings.resx | 3 - src/MSBuild/Resources/xlf/Strings.cs.xlf | 5 +- src/MSBuild/Resources/xlf/Strings.de.xlf | 5 +- src/MSBuild/Resources/xlf/Strings.es.xlf | 5 +- src/MSBuild/Resources/xlf/Strings.fr.xlf | 5 +- src/MSBuild/Resources/xlf/Strings.it.xlf | 5 +- src/MSBuild/Resources/xlf/Strings.ja.xlf | 5 +- src/MSBuild/Resources/xlf/Strings.ko.xlf | 5 +- src/MSBuild/Resources/xlf/Strings.pl.xlf | 5 +- src/MSBuild/Resources/xlf/Strings.pt-BR.xlf | 5 +- src/MSBuild/Resources/xlf/Strings.ru.xlf | 5 +- src/MSBuild/Resources/xlf/Strings.tr.xlf | 5 +- src/MSBuild/Resources/xlf/Strings.zh-Hans.xlf | 5 +- src/MSBuild/Resources/xlf/Strings.zh-Hant.xlf | 5 +- src/MSBuild/XMake.cs | 1 - src/UnitTests.Shared/EngineTestEnvironment.cs | 9 - 22 files changed, 53 insertions(+), 1319 deletions(-) delete mode 100644 src/Build/Logging/SerialConsoleLogger.cs diff --git a/src/Build.UnitTests/BinaryLogger_Tests.cs b/src/Build.UnitTests/BinaryLogger_Tests.cs index 9334bcf5314..09f6c8bf529 100644 --- a/src/Build.UnitTests/BinaryLogger_Tests.cs +++ b/src/Build.UnitTests/BinaryLogger_Tests.cs @@ -108,10 +108,6 @@ public void TestBinaryLoggerRoundtrip(string projectText, BinlogRoundtripTestRep var mockLogFromBuild = new MockLogger(); - var serialFromBuildText = new StringBuilder(); - var serialFromBuild = new SerialConsoleLogger(Framework.LoggerVerbosity.Diagnostic, t => serialFromBuildText.Append(t), colorSet: null, colorReset: null); - serialFromBuild.Parameters = "NOPERFORMANCESUMMARY"; - var parallelFromBuildText = new StringBuilder(); var parallelFromBuild = new ParallelConsoleLogger(Framework.LoggerVerbosity.Diagnostic, t => parallelFromBuildText.Append(t), colorSet: null, colorReset: null); parallelFromBuild.Parameters = "NOPERFORMANCESUMMARY"; @@ -121,7 +117,7 @@ public void TestBinaryLoggerRoundtrip(string projectText, BinlogRoundtripTestRep using (ProjectCollection collection = new()) { Project project = ObjectModelHelpers.CreateInMemoryProject(collection, projectText); - project.Build(new ILogger[] { binaryLogger, mockLogFromBuild, serialFromBuild, parallelFromBuild }).ShouldBeTrue(); + project.Build(new ILogger[] { binaryLogger, mockLogFromBuild, parallelFromBuild }).ShouldBeTrue(); } string fileToReplay; @@ -156,34 +152,25 @@ public void TestBinaryLoggerRoundtrip(string projectText, BinlogRoundtripTestRep var mockLogFromPlayback = new MockLogger(); - var serialFromPlaybackText = new StringBuilder(); - var serialFromPlayback = new SerialConsoleLogger(Framework.LoggerVerbosity.Diagnostic, t => serialFromPlaybackText.Append(t), colorSet: null, colorReset: null); - serialFromPlayback.Parameters = "NOPERFORMANCESUMMARY"; - var parallelFromPlaybackText = new StringBuilder(); var parallelFromPlayback = new ParallelConsoleLogger(Framework.LoggerVerbosity.Diagnostic, t => parallelFromPlaybackText.Append(t), colorSet: null, colorReset: null); parallelFromPlayback.Parameters = "NOPERFORMANCESUMMARY"; var binaryLogReader = new BinaryLogReplayEventSource(); mockLogFromPlayback.Initialize(binaryLogReader); - serialFromPlayback.Initialize(binaryLogReader); parallelFromPlayback.Initialize(binaryLogReader); // read the binary log and replay into mockLogger2 binaryLogReader.Replay(fileToReplay); mockLogFromPlayback.Shutdown(); - serialFromPlayback.Shutdown(); parallelFromPlayback.Shutdown(); // the binlog will have more information than recorded by the text log mockLogFromPlayback.FullLog.ShouldContainWithoutWhitespace(mockLogFromBuild.FullLog); - var serialExpected = serialFromBuildText.ToString(); - var serialActual = serialFromPlaybackText.ToString(); var parallelExpected = parallelFromBuildText.ToString(); var parallelActual = parallelFromPlaybackText.ToString(); - serialActual.ShouldContainWithoutWhitespace(serialExpected); parallelActual.ShouldContainWithoutWhitespace(parallelExpected); } diff --git a/src/Build.UnitTests/ConsoleLogger_Tests.cs b/src/Build.UnitTests/ConsoleLogger_Tests.cs index 67cce196758..c1dec84bb6e 100644 --- a/src/Build.UnitTests/ConsoleLogger_Tests.cs +++ b/src/Build.UnitTests/ConsoleLogger_Tests.cs @@ -564,7 +564,6 @@ public void NullEventFieldsParallel() [Theory] public void TestVerbosityLessThan(LoggerVerbosity loggerVerbosity, LoggerVerbosity checkVerbosity, bool expectedResult) { - new SerialConsoleLogger(loggerVerbosity).IsVerbosityAtLeast(checkVerbosity).ShouldBe(expectedResult); new ParallelConsoleLogger(loggerVerbosity).IsVerbosityAtLeast(checkVerbosity).ShouldBe(expectedResult); } @@ -1191,58 +1190,6 @@ public void TestDirectEventHandlers() } } - [Fact] - public void SingleLineFormatNoop() - { - string s = "foo"; - SerialConsoleLogger cl = new SerialConsoleLogger(); - - string ss = cl.IndentString(s, 0); - - // should be a no-op - ss.ShouldBe($"foo{Environment.NewLine}"); - } - - [Fact] - public void MultilineFormatWindowsLineEndings() - { - string newline = "\r\n"; - string s = "foo" + newline + "bar" + - newline + "baz" + newline; - SerialConsoleLogger cl = new SerialConsoleLogger(); - - string ss = cl.IndentString(s, 4); - - // should convert lines to system format - ss.ShouldBe($" foo{Environment.NewLine} bar{Environment.NewLine} baz{Environment.NewLine} {Environment.NewLine}"); - } - - [Fact] - public void MultilineFormatUnixLineEndings() - { - string s = "foo\nbar\nbaz\n"; - SerialConsoleLogger cl = new SerialConsoleLogger(); - - string ss = cl.IndentString(s, 0); - - // should convert lines to system format - ss.ShouldBe($"foo{Environment.NewLine}bar{Environment.NewLine}baz{Environment.NewLine}{Environment.NewLine}"); - } - - [Fact] - public void MultilineFormatMixedLineEndings() - { - string s = "\n" + "foo" + "\r\n\r\n" + "bar" + "\n" + "baz" + "\n\r\n\n" + - "jazz" + "\r\n" + "razz" + "\n\n" + "matazz" + "\n" + "end"; - - SerialConsoleLogger cl = new SerialConsoleLogger(); - - string ss = cl.IndentString(s, 0); - - // should convert lines to system format - ss.ShouldBe($"{Environment.NewLine}foo{Environment.NewLine}{Environment.NewLine}bar{Environment.NewLine}baz{Environment.NewLine}{Environment.NewLine}{Environment.NewLine}jazz{Environment.NewLine}razz{Environment.NewLine}{Environment.NewLine}matazz{Environment.NewLine}end{Environment.NewLine}"); - } - [Fact] public void NestedProjectMinimal() { @@ -1425,23 +1372,13 @@ private void WriteAndValidateProperties(BaseConsoleLogger cl, SimulatedConsole s string prop1; string prop2; string prop3; - if (cl is SerialConsoleLogger scl) - { - var propertyList = scl.ExtractPropertyList(properties); - scl.WriteProperties(propertyList); - prop1 = String.Format(CultureInfo.CurrentCulture, "{0,-30} = {1}", "prop1", "val1"); - prop2 = String.Format(CultureInfo.CurrentCulture, "{0,-30} = {1}", "prop2", "val2"); - prop3 = String.Format(CultureInfo.CurrentCulture, "{0,-30} = {1}", "pro(p3)", "va;%3b;l3"); - } - else - { - BuildEventArgs buildEvent = new BuildErrorEventArgs("", "", "", 0, 0, 0, 0, "", "", ""); - buildEvent.BuildEventContext = new BuildEventContext(1, 2, 3, 4); - ((ParallelConsoleLogger)cl).WriteProperties(buildEvent, properties); - prop1 = String.Format(CultureInfo.CurrentCulture, "{0} = {1}", "prop1", "val1"); - prop2 = String.Format(CultureInfo.CurrentCulture, "{0} = {1}", "prop2", "val2"); - prop3 = String.Format(CultureInfo.CurrentCulture, "{0} = {1}", "pro(p3)", "va;%3b;l3"); - } + + BuildEventArgs buildEvent = new BuildErrorEventArgs("", "", "", 0, 0, 0, 0, "", "", ""); + buildEvent.BuildEventContext = new BuildEventContext(1, 2, 3, 4); + ((ParallelConsoleLogger)cl).WriteProperties(buildEvent, properties); + prop1 = String.Format(CultureInfo.CurrentCulture, "{0} = {1}", "prop1", "val1"); + prop2 = String.Format(CultureInfo.CurrentCulture, "{0} = {1}", "prop2", "val2"); + prop3 = String.Format(CultureInfo.CurrentCulture, "{0} = {1}", "pro(p3)", "va;%3b;l3"); string log = sc.ToString(); _output.WriteLine("[" + log + "]"); @@ -1468,11 +1405,7 @@ private void WriteAndValidateProperties(BaseConsoleLogger cl, SimulatedConsole s public void DisplayPropertiesList() { SimulatedConsole sc = new SimulatedConsole(); - SerialConsoleLogger cl = new SerialConsoleLogger(LoggerVerbosity.Diagnostic, sc.Write, null, null); - - WriteAndValidateProperties(cl, sc, true); - - sc = new SimulatedConsole(); + ParallelConsoleLogger cl2 = new ParallelConsoleLogger(LoggerVerbosity.Diagnostic, sc.Write, null, null); EventSourceSink es = new EventSourceSink(); cl2.Initialize(es); @@ -1487,9 +1420,6 @@ public void DisplayPropertiesList() public void DoNotDisplayPropertiesListInDetailed() { SimulatedConsole sc = new SimulatedConsole(); - SerialConsoleLogger cl = new SerialConsoleLogger(LoggerVerbosity.Detailed, sc.Write, null, null); - - WriteAndValidateProperties(cl, sc, false); sc = new SimulatedConsole(); ParallelConsoleLogger cl2 = new ParallelConsoleLogger(LoggerVerbosity.Detailed, sc.Write, null, null); @@ -1505,18 +1435,12 @@ public void DoNotDisplayPropertiesListInDetailed() public void DoNotDisplayEnvironmentInDetailed() { SimulatedConsole sc = new SimulatedConsole(); - SerialConsoleLogger cl = new SerialConsoleLogger(LoggerVerbosity.Detailed, sc.Write, null, null); - WriteEnvironment(cl, sc, false); - - sc = new SimulatedConsole(); ParallelConsoleLogger cl2 = new ParallelConsoleLogger(LoggerVerbosity.Detailed, sc.Write, null, null); WriteEnvironment(cl2, sc, false); } - - /// /// Basic test of environment list not being displayed except in Diagnostic or if the showenvironment flag is set /// @@ -1524,12 +1448,7 @@ public void DoNotDisplayEnvironmentInDetailed() public void DisplayEnvironmentInDetailed() { SimulatedConsole sc = new SimulatedConsole(); - SerialConsoleLogger cl = new SerialConsoleLogger(LoggerVerbosity.Detailed, sc.Write, null, null); - cl.Parameters = "ShowEnvironment"; - cl.ParseParameters(); - WriteEnvironment(cl, sc, true); - sc = new SimulatedConsole(); ParallelConsoleLogger cl2 = new ParallelConsoleLogger(LoggerVerbosity.Detailed, sc.Write, null, null); EventSourceSink es = new EventSourceSink(); cl2.Initialize(es); @@ -1546,10 +1465,7 @@ public void DisplayEnvironmentInDetailed() public void DisplayEnvironmentInDiagnostic() { SimulatedConsole sc = new SimulatedConsole(); - SerialConsoleLogger cl = new SerialConsoleLogger(LoggerVerbosity.Diagnostic, sc.Write, null, null); - WriteEnvironment(cl, sc, true); - sc = new SimulatedConsole(); ParallelConsoleLogger cl2 = new ParallelConsoleLogger(LoggerVerbosity.Diagnostic, sc.Write, null, null); EventSourceSink es = new EventSourceSink(); cl2.Initialize(es); @@ -1563,18 +1479,12 @@ public void DisplayEnvironmentInDiagnostic() public void DoNotDisplayEnvironmentInMinimal() { SimulatedConsole sc = new SimulatedConsole(); - SerialConsoleLogger cl = new SerialConsoleLogger(LoggerVerbosity.Minimal, sc.Write, null, null); - - WriteEnvironment(cl, sc, false); - sc = new SimulatedConsole(); ParallelConsoleLogger cl2 = new ParallelConsoleLogger(LoggerVerbosity.Minimal, sc.Write, null, null); WriteEnvironment(cl2, sc, false); } - - /// /// Basic test of environment list not being displayed except in Diagnostic or if the showenvironment flag is set /// @@ -1582,12 +1492,7 @@ public void DoNotDisplayEnvironmentInMinimal() public void DisplayEnvironmentInMinimal() { SimulatedConsole sc = new SimulatedConsole(); - SerialConsoleLogger cl = new SerialConsoleLogger(LoggerVerbosity.Minimal, sc.Write, null, null); - cl.Parameters = "ShowEnvironment"; - cl.ParseParameters(); - WriteEnvironment(cl, sc, true); - - sc = new SimulatedConsole(); + ParallelConsoleLogger cl2 = new ParallelConsoleLogger(LoggerVerbosity.Minimal, sc.Write, null, null); EventSourceSink es = new EventSourceSink(); cl2.Initialize(es); @@ -1604,21 +1509,14 @@ public void DisplayEnvironmentInMinimal() public void DoNotDisplayPropertiesListIfDisabled() { SimulatedConsole sc = new SimulatedConsole(); - SerialConsoleLogger cl = new SerialConsoleLogger(LoggerVerbosity.Diagnostic, sc.Write, null, null); - cl.Parameters = "noitemandpropertylist"; - cl.ParseParameters(); - - WriteAndValidateProperties(cl, sc, false); - sc = new SimulatedConsole(); ParallelConsoleLogger cl2 = new ParallelConsoleLogger(LoggerVerbosity.Diagnostic, sc.Write, null, null); cl2.Parameters = "noitemandpropertylist"; cl2.ParseParameters(); - WriteAndValidateProperties(cl, sc, false); + WriteAndValidateProperties(cl2, sc, false); } - /// /// Create some items and log them /// @@ -1680,24 +1578,12 @@ private void WriteAndValidateItems(BaseConsoleLogger cl, SimulatedConsole sc, bo string item3spec; string item3metadatum = string.Empty; - if (cl is SerialConsoleLogger scl) - { - SortedList itemList = scl.ExtractItemList(items); - scl.WriteItems(itemList); - item1spec = "spec" + Environment.NewLine; - item2spec = "spec2" + Environment.NewLine; - item3spec = "(spec;3" + Environment.NewLine; - item3metadatum = "f)oo = !@#" + Environment.NewLine; - } - else - { - BuildEventArgs buildEvent = new BuildErrorEventArgs("", "", "", 0, 0, 0, 0, "", "", ""); - buildEvent.BuildEventContext = new BuildEventContext(1, 2, 3, 4); - ((ParallelConsoleLogger)cl).WriteItems(buildEvent, items); - item1spec = Environment.NewLine + " spec" + Environment.NewLine; - item2spec = Environment.NewLine + " spec2" + Environment.NewLine; - item3spec = Environment.NewLine + " (spec;3" + Environment.NewLine; - } + BuildEventArgs buildEvent = new BuildErrorEventArgs("", "", "", 0, 0, 0, 0, "", "", ""); + buildEvent.BuildEventContext = new BuildEventContext(1, 2, 3, 4); + ((ParallelConsoleLogger)cl).WriteItems(buildEvent, items); + item1spec = Environment.NewLine + " spec" + Environment.NewLine; + item2spec = Environment.NewLine + " spec2" + Environment.NewLine; + item3spec = Environment.NewLine + " (spec;3" + Environment.NewLine; item1type = "type" + Environment.NewLine; item2type = "type2" + Environment.NewLine; @@ -1707,8 +1593,6 @@ private void WriteAndValidateItems(BaseConsoleLogger cl, SimulatedConsole sc, bo _output.WriteLine("[" + log + "]"); - - // Being careful not to make locale assumptions here, eg about sorting if (expectToSeeLogging) { @@ -1749,37 +1633,15 @@ public void WriteItemsEmptyList() { Hashtable items = new Hashtable(); - for (int i = 0; i < 2; i++) - { - BaseConsoleLogger cl = null; - SimulatedConsole sc = new SimulatedConsole(); - if (i == 0) - { - cl = new SerialConsoleLogger(LoggerVerbosity.Diagnostic, sc.Write, null, null); - } - else - { - cl = new ParallelConsoleLogger(LoggerVerbosity.Diagnostic, sc.Write, null, null); - } - - if (cl is SerialConsoleLogger scl) - { - SortedList itemList = scl.ExtractItemList(items); - scl.WriteItems(itemList); - } - else - { - BuildEventArgs buildEvent = new BuildErrorEventArgs("", "", "", 0, 0, 0, 0, "", "", ""); - buildEvent.BuildEventContext = new BuildEventContext(1, 2, 3, 4); - ((ParallelConsoleLogger)cl).WriteItems(buildEvent, items); - } - - string log = sc.ToString(); + SimulatedConsole sc = new SimulatedConsole(); + BaseConsoleLogger cl = new ParallelConsoleLogger(LoggerVerbosity.Diagnostic, sc.Write, null, null); + BuildEventArgs buildEvent = new BuildErrorEventArgs("", "", "", 0, 0, 0, 0, "", "", ""); + buildEvent.BuildEventContext = new BuildEventContext(1, 2, 3, 4); + ((ParallelConsoleLogger)cl).WriteItems(buildEvent, items); + string log = sc.ToString(); - // There should be nothing in the log - log.Length.ShouldBe(0); - _output.WriteLine("Iteration of i: " + i + "[" + log + "]"); - } + // There should be nothing in the log + log.Length.ShouldBe(0); } /// @@ -1791,29 +1653,16 @@ public void WritePropertiesEmptyList() { Hashtable properties = new Hashtable(); - for (int i = 0; i < 2; i++) - { - SimulatedConsole sc = new SimulatedConsole(); - if (i == 0) - { - var cl = new SerialConsoleLogger(LoggerVerbosity.Diagnostic, sc.Write, null, null); - var propertyList = cl.ExtractPropertyList(properties); - cl.WriteProperties(propertyList); - } - else - { - var cl = new ParallelConsoleLogger(LoggerVerbosity.Diagnostic, sc.Write, null, null); - BuildEventArgs buildEvent = new BuildErrorEventArgs("", "", "", 0, 0, 0, 0, "", "", ""); - buildEvent.BuildEventContext = new BuildEventContext(1, 2, 3, 4); - cl.WriteProperties(buildEvent, properties); - } + SimulatedConsole sc = new SimulatedConsole(); + var cl = new ParallelConsoleLogger(LoggerVerbosity.Diagnostic, sc.Write, null, null); + BuildEventArgs buildEvent = new BuildErrorEventArgs("", "", "", 0, 0, 0, 0, "", "", ""); + buildEvent.BuildEventContext = new BuildEventContext(1, 2, 3, 4); + cl.WriteProperties(buildEvent, properties); - string log = sc.ToString(); + string log = sc.ToString(); - // There should be nothing in the log - log.Length.ShouldBe(0); - _output.WriteLine("Iteration of i: " + i + "[" + log + "]"); - } + // There should be nothing in the log + log.Length.ShouldBe(0); } /// @@ -1823,11 +1672,7 @@ public void WritePropertiesEmptyList() public void DisplayItemsList() { SimulatedConsole sc = new SimulatedConsole(); - SerialConsoleLogger cl = new SerialConsoleLogger(LoggerVerbosity.Diagnostic, sc.Write, null, null); - - WriteAndValidateItems(cl, sc, true); - sc = new SimulatedConsole(); ParallelConsoleLogger cl2 = new ParallelConsoleLogger(LoggerVerbosity.Diagnostic, sc.Write, null, null); EventSourceSink es = new EventSourceSink(); cl2.Initialize(es); @@ -1842,11 +1687,7 @@ public void DisplayItemsList() public void DoNotDisplayItemListInDetailed() { SimulatedConsole sc = new SimulatedConsole(); - SerialConsoleLogger cl = new SerialConsoleLogger(LoggerVerbosity.Detailed, sc.Write, null, null); - - WriteAndValidateItems(cl, sc, false); - sc = new SimulatedConsole(); ParallelConsoleLogger cl2 = new ParallelConsoleLogger(LoggerVerbosity.Detailed, sc.Write, null, null); WriteAndValidateItems(cl2, sc, false); @@ -1859,13 +1700,7 @@ public void DoNotDisplayItemListInDetailed() public void DoNotDisplayItemListIfDisabled() { SimulatedConsole sc = new SimulatedConsole(); - SerialConsoleLogger cl = new SerialConsoleLogger(LoggerVerbosity.Diagnostic, sc.Write, null, null); - cl.Parameters = "noitemandpropertylist"; - cl.ParseParameters(); - - WriteAndValidateItems(cl, sc, false); - sc = new SimulatedConsole(); ParallelConsoleLogger cl2 = new ParallelConsoleLogger(LoggerVerbosity.Diagnostic, sc.Write, null, null); cl2.Parameters = "noitemandpropertylist"; cl2.ParseParameters(); @@ -1877,17 +1712,7 @@ public void DoNotDisplayItemListIfDisabled() public void ParametersEmptyTests() { SimulatedConsole sc = new SimulatedConsole(); - SerialConsoleLogger L = new SerialConsoleLogger(LoggerVerbosity.Normal, sc.Write, null, null); - - L.Parameters = ""; - L.ParseParameters(); - L.ShowSummary.ShouldBeNull(); - L.Parameters = null; - L.ParseParameters(); - L.ShowSummary.ShouldBeNull(); - - sc = new SimulatedConsole(); ParallelConsoleLogger cl2 = new ParallelConsoleLogger(LoggerVerbosity.Diagnostic, sc.Write, null, null); cl2.Parameters = "noitemandpropertylist"; cl2.ParseParameters(); @@ -1899,29 +1724,13 @@ public void ParametersEmptyTests() public void ParametersParsingTests() { SimulatedConsole sc = new SimulatedConsole(); - SerialConsoleLogger L = new SerialConsoleLogger(LoggerVerbosity.Normal, sc.Write, null, null); - L.Parameters = "NoSuMmaRy"; - L.ParseParameters(); - L.ShowSummary.ShouldNotBeNull(); - ((bool)L.ShowSummary).ShouldBeFalse(); + ParallelConsoleLogger L = new ParallelConsoleLogger(LoggerVerbosity.Normal, sc.Write, null, null); L.Parameters = ";;NoSuMmaRy;"; L.ParseParameters(); L.ShowSummary.ShouldNotBeNull(); - ((bool)L.ShowSummary).ShouldBeFalse(); - sc = new SimulatedConsole(); - ParallelConsoleLogger L2 = new ParallelConsoleLogger(LoggerVerbosity.Normal, sc.Write, null, null); - - L2.Parameters = "NoSuMmaRy"; - L2.ParseParameters(); - L.ShowSummary.ShouldNotBeNull(); - ((bool)L.ShowSummary).ShouldBeFalse(); - - L2.Parameters = ";;NoSuMmaRy;"; - L2.ParseParameters(); - L.ShowSummary.ShouldNotBeNull(); ((bool)L.ShowSummary).ShouldBeFalse(); } diff --git a/src/Build/Logging/ConsoleLogger.cs b/src/Build/Logging/ConsoleLogger.cs index 41bfaf94f50..bffd841fcad 100644 --- a/src/Build/Logging/ConsoleLogger.cs +++ b/src/Build/Logging/ConsoleLogger.cs @@ -8,8 +8,6 @@ using Microsoft.Build.Framework.Telemetry; using Microsoft.Build.Shared; using BaseConsoleLogger = Microsoft.Build.BackEnd.Logging.BaseConsoleLogger; -using ParallelConsoleLogger = Microsoft.Build.BackEnd.Logging.ParallelConsoleLogger; -using SerialConsoleLogger = Microsoft.Build.BackEnd.Logging.SerialConsoleLogger; #nullable disable @@ -40,14 +38,12 @@ namespace Microsoft.Build.Logging /// /// This class implements the default logger that outputs event data /// to the console (stdout). - /// It is a facade: it creates, wraps and delegates to a kind of BaseConsoleLogger, - /// either SerialConsoleLogger or ParallelConsoleLogger. + /// It is a facade: it creates, wraps and delegates to a kind of BaseConsoleLogger or ParallelConsoleLogger. /// /// This class is not thread safe. public class ConsoleLogger : INodeLogger { private BaseConsoleLogger _consoleLogger; - private int _numberOfProcessors = 1; private LoggerVerbosity _verbosity; private WriteHandler _write; private ColorSetter _colorSet; @@ -108,7 +104,6 @@ private void InitializeBaseConsoleLogger() return; } - bool useMPLogger = false; bool disableConsoleColor = false; bool forceConsoleColor = false; bool preferConsoleColor = false; @@ -122,14 +117,6 @@ private void InitializeBaseConsoleLogger() continue; } - if (string.Equals(param, "ENABLEMPLOGGING", StringComparison.OrdinalIgnoreCase)) - { - useMPLogger = true; - } - if (string.Equals(param, "DISABLEMPLOGGING", StringComparison.OrdinalIgnoreCase)) - { - useMPLogger = false; - } if (string.Equals(param, "DISABLECONSOLECOLOR", StringComparison.OrdinalIgnoreCase)) { disableConsoleColor = true; @@ -157,29 +144,14 @@ private void InitializeBaseConsoleLogger() _colorReset = BaseConsoleLogger.DontResetColor; } - if (_numberOfProcessors == 1 && !useMPLogger) + _consoleLogger = new ParallelConsoleLogger(_verbosity, _write, _colorSet, _colorReset); + if (this is FileLogger) { - _consoleLogger = new SerialConsoleLogger(_verbosity, _write, _colorSet, _colorReset); - if (this is FileLogger) - { - KnownTelemetry.LoggingConfigurationTelemetry.FileLoggerType = "serial"; - } - else - { - KnownTelemetry.LoggingConfigurationTelemetry.ConsoleLoggerType = "serial"; - } + KnownTelemetry.LoggingConfigurationTelemetry.FileLoggerType = "parallel"; } else { - _consoleLogger = new ParallelConsoleLogger(_verbosity, _write, _colorSet, _colorReset); - if (this is FileLogger) - { - KnownTelemetry.LoggingConfigurationTelemetry.FileLoggerType = "parallel"; - } - else - { - KnownTelemetry.LoggingConfigurationTelemetry.ConsoleLoggerType = "parallel"; - } + KnownTelemetry.LoggingConfigurationTelemetry.ConsoleLoggerType = "parallel"; } if (_showSummary != null) @@ -354,7 +326,6 @@ public virtual void Initialize(IEventSource eventSource) /// public virtual void Initialize(IEventSource eventSource, int nodeCount) { - _numberOfProcessors = nodeCount; InitializeBaseConsoleLogger(); _consoleLogger.Initialize(eventSource, nodeCount); diff --git a/src/Build/Logging/ParallelLogger/ParallelConsoleLogger.cs b/src/Build/Logging/ParallelLogger/ParallelConsoleLogger.cs index fb60ed2c23c..bbc114d14d2 100644 --- a/src/Build/Logging/ParallelLogger/ParallelConsoleLogger.cs +++ b/src/Build/Logging/ParallelLogger/ParallelConsoleLogger.cs @@ -812,6 +812,7 @@ internal void WriteItems(BuildEventArgs e, IEnumerable items) { return; } + WriteLinePrefix(e.BuildEventContext, e.Timestamp, false); WriteItems(itemList); ShownBuildEventContext(e.BuildEventContext); diff --git a/src/Build/Logging/SerialConsoleLogger.cs b/src/Build/Logging/SerialConsoleLogger.cs deleted file mode 100644 index ebd8c4520ea..00000000000 --- a/src/Build/Logging/SerialConsoleLogger.cs +++ /dev/null @@ -1,981 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using Microsoft.Build.Framework; -using Microsoft.Build.Shared; -using ColorResetter = Microsoft.Build.Logging.ColorResetter; -using ColorSetter = Microsoft.Build.Logging.ColorSetter; -using WriteHandler = Microsoft.Build.Logging.WriteHandler; - -#nullable disable - -namespace Microsoft.Build.BackEnd.Logging -{ - internal class SerialConsoleLogger : BaseConsoleLogger - { - #region Constructors - - /// - /// Default constructor. - /// - public SerialConsoleLogger() - : this(LoggerVerbosity.Normal) - { - // do nothing - } - - /// - /// Create a logger instance with a specific verbosity. This logs to - /// the default console. - /// - /// Verbosity level. - public SerialConsoleLogger(LoggerVerbosity verbosity) - : - this - ( - verbosity, - new WriteHandler(Console.Out.Write), - new ColorSetter(SetColor), - new ColorResetter(ResetColor)) - { - // do nothing - } - - /// - /// Initializes the logger, with alternate output handlers. - /// - /// - /// - /// - /// - public SerialConsoleLogger( - LoggerVerbosity verbosity, - WriteHandler write, - ColorSetter colorSet, - ColorResetter colorReset) - { - InitializeConsoleMethods(verbosity, write, colorSet, colorReset); - } - - #endregion - - #region Methods - - /// - /// Reset the states of per-build member variables - /// VSW#516376 - /// - internal override void ResetConsoleLoggerState() - { - if (ShowSummary == true) - { - errorList = new List(); - warningList = new List(); - } - else - { - errorList = null; - warningList = null; - } - - errorCount = 0; - warningCount = 0; - - projectPerformanceCounters = null; - targetPerformanceCounters = null; - taskPerformanceCounters = null; - } - - /// - /// Handler for build started events - /// - /// sender (should be null) - /// event arguments - public override void BuildStartedHandler(object sender, BuildStartedEventArgs e) - { - buildStarted = e.Timestamp; - - if (ShowSummary == true) - { - WriteLinePrettyFromResource("BuildStartedWithTime", e.Timestamp); - } - - if (Traits.LogAllEnvironmentVariables) - { - WriteEnvironment(e.BuildEnvironment); - } - else - { - WriteEnvironment(e.BuildEnvironment?.Where(kvp => EnvironmentUtilities.IsWellKnownEnvironmentDerivedProperty(kvp.Key)).ToDictionary(kvp => kvp.Key, kvp => kvp.Value)); - } - } - - /// - /// Handler for build finished events - /// - /// sender (should be null) - /// event arguments - public override void BuildFinishedHandler(object sender, BuildFinishedEventArgs e) - { - // Show the performance summary if the verbosity is diagnostic or the user specifically asked for it - // with a logger parameter. - if (this.showPerfSummary) - { - ShowPerfSummary(); - } - - if (ShowSummary == true) - { - if (e.Succeeded) - { - setColor(ConsoleColor.Green); - } - - // Write the "Build Finished" event. - WriteNewLine(); - WriteLinePretty(e.Message); - - resetColor(); - } - - // The decision whether or not to show a summary at this verbosity - // was made during initialization. We just do what we're told. - if (ShowSummary == true) - { - ShowErrorWarningSummary(); - - if (IsVerbosityAtLeast(LoggerVerbosity.Normal)) - { - // Emit text like: - // 1 Warning(s) - // 0 Error(s) - // Don't color the line if it's zero. (Per Whidbey behavior.) - if (warningCount > 0) - { - setColor(ConsoleColor.Yellow); - } - WriteLinePrettyFromResource(2, "WarningCount", warningCount); - resetColor(); - - if (errorCount > 0) - { - setColor(ConsoleColor.Red); - } - WriteLinePrettyFromResource(2, "ErrorCount", errorCount); - resetColor(); - } - } - - if (ShowSummary == true) - { - string timeElapsed = LogFormatter.FormatTimeSpan(e.Timestamp - buildStarted); - - WriteNewLine(); - WriteLinePrettyFromResource("TimeElapsed", timeElapsed); - } - - ResetConsoleLoggerState(); - } - - /// - /// At the end of the build, repeats the errors and warnings that occurred - /// during the build, and displays the error count and warning count. - /// - private void ShowErrorWarningSummary() - { - if (warningCount == 0 && errorCount == 0) - { - return; - } - - // Make some effort to distinguish the summary from the previous output - WriteNewLine(); - - if (warningCount > 0) - { - setColor(ConsoleColor.Yellow); - foreach (BuildWarningEventArgs warningEventArgs in warningList) - { - WriteLinePretty(EventArgsFormatting.FormatEventMessage(warningEventArgs, showProjectFile)); - } - } - - if (errorCount > 0) - { - setColor(ConsoleColor.Red); - foreach (BuildErrorEventArgs errorEventArgs in errorList) - { - WriteLinePretty(EventArgsFormatting.FormatEventMessage(errorEventArgs, showProjectFile)); - } - } - - resetColor(); - } - - /// - /// Handler for project started events - /// - /// sender (should be null) - /// event arguments - public override void ProjectStartedHandler(object sender, ProjectStartedEventArgs e) - { - if (!contextStack.IsEmpty()) - { - this.VerifyStack(contextStack.Peek().type == FrameType.Target, "Bad stack -- Top is project {0}", contextStack.Peek().ID); - } - - // if verbosity is normal, detailed or diagnostic - if (IsVerbosityAtLeast(LoggerVerbosity.Normal) && ShowSummary != false) - { - ShowDeferredMessages(); - - // check for stack corruption - if (!contextStack.IsEmpty()) - { - this.VerifyStack(contextStack.Peek().type == FrameType.Target, "Bad stack -- Top is target {0}", contextStack.Peek().ID); - } - - contextStack.Push(new Frame(FrameType.Project, - false, // message not yet displayed - this.currentIndentLevel, - e.ProjectFile, - e.TargetNames, - null, - GetCurrentlyBuildingProjectFile())); - WriteProjectStarted(); - } - else - { - contextStack.Push(new Frame(FrameType.Project, - false, // message not yet displayed - this.currentIndentLevel, - e.ProjectFile, - e.TargetNames, - null, - GetCurrentlyBuildingProjectFile())); - } - - if (this.showPerfSummary) - { - PerformanceCounter counter = GetPerformanceCounter(e.ProjectFile, ref projectPerformanceCounters); - - // Place the counter "in scope" meaning the project is executing right now. - counter.InScope = true; - } - - if (Verbosity == LoggerVerbosity.Diagnostic && showItemAndPropertyList) - { - if (e.Properties != null) - { - var propertyList = ExtractPropertyList(e.Properties); - WriteProperties(propertyList); - } - - if (e.Items != null) - { - SortedList itemList = ExtractItemList(e.Items); - WriteItems(itemList); - } - } - } - - /// - /// Handler for project finished events - /// - /// sender (should be null) - /// event arguments - public override void ProjectFinishedHandler(object sender, ProjectFinishedEventArgs e) - { - if (this.showPerfSummary) - { - PerformanceCounter counter = GetPerformanceCounter(e.ProjectFile, ref projectPerformanceCounters); - - // Place the counter "in scope" meaning the project is done executing right now. - counter.InScope = false; - } - - // if verbosity is detailed or diagnostic, - // or there was an error or warning - if (contextStack.Peek().hasErrorsOrWarnings - || (IsVerbosityAtLeast(LoggerVerbosity.Detailed))) - { - setColor(ConsoleColor.Cyan); - - if (IsVerbosityAtLeast(LoggerVerbosity.Normal)) - { - WriteNewLine(); - } - - WriteLinePretty(e.Message); - - resetColor(); - } - - Frame top = contextStack.Pop(); - - this.VerifyStack(top.type == FrameType.Project, "Unexpected project frame {0}", top.ID); - this.VerifyStack(top.ID == e.ProjectFile, "Project frame {0} expected, but was {1}.", e.ProjectFile, top.ID); - } - - /// - /// Handler for target started events - /// - /// sender (should be null) - /// event arguments - public override void TargetStartedHandler(object sender, TargetStartedEventArgs e) - { - contextStack.Push(new Frame(FrameType.Target, - false, - this.currentIndentLevel, - e.TargetName, - null, - e.TargetFile, - GetCurrentlyBuildingProjectFile())); - - // if verbosity is detailed or diagnostic - if (IsVerbosityAtLeast(LoggerVerbosity.Detailed)) - { - WriteTargetStarted(); - } - - if (this.showPerfSummary) - { - PerformanceCounter counter = GetPerformanceCounter(e.TargetName, ref targetPerformanceCounters); - - // Place the counter "in scope" meaning the target is executing right now. - counter.InScope = true; - } - - // Bump up the overall number of indents, so that anything within this target will show up - // indented. - this.currentIndentLevel++; - } - - /// - /// Handler for target finished events - /// - /// sender (should be null) - /// event arguments - public override void TargetFinishedHandler(object sender, TargetFinishedEventArgs e) - { - // Done with the target, so shift everything left again. - this.currentIndentLevel--; - - if (this.showPerfSummary) - { - PerformanceCounter counter = GetPerformanceCounter(e.TargetName, ref targetPerformanceCounters); - - // Place the counter "in scope" meaning the target is done executing right now. - counter.InScope = false; - } - - bool targetHasErrorsOrWarnings = contextStack.Peek().hasErrorsOrWarnings; - - // if verbosity is diagnostic, - // or there was an error or warning and verbosity is normal or detailed - if ((targetHasErrorsOrWarnings && (IsVerbosityAtLeast(LoggerVerbosity.Normal))) - || Verbosity == LoggerVerbosity.Diagnostic) - { - setColor(ConsoleColor.Cyan); - - if (showTargetOutputs) - { - IEnumerable targetOutputs = e.TargetOutputs; - - if (targetOutputs != null) - { - WriteLinePretty(ResourceUtilities.GetResourceString("TargetOutputItemsHeader")); - foreach (ITaskItem item in targetOutputs) - { - WriteLinePretty(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("TargetOutputItem", item.ItemSpec)); - } - } - } - - WriteLinePretty(e.Message); - resetColor(); - } - - Frame top = contextStack.Pop(); - this.VerifyStack(top.type == FrameType.Target, "bad stack frame type"); - this.VerifyStack(top.ID == e.TargetName, "bad stack frame id"); - - // set the value on the Project frame, for the ProjectFinished handler - if (targetHasErrorsOrWarnings) - { - SetErrorsOrWarningsOnCurrentFrame(); - } - } - - /// - /// Handler for task started events - /// - /// sender (should be null) - /// event arguments - public override void TaskStartedHandler(object sender, TaskStartedEventArgs e) - { - // if verbosity is detailed or diagnostic - if (IsVerbosityAtLeast(LoggerVerbosity.Detailed)) - { - setColor(ConsoleColor.Cyan); - WriteLinePretty(e.Message); - resetColor(); - } - - if (this.showPerfSummary) - { - PerformanceCounter counter = GetPerformanceCounter(e.TaskName, ref taskPerformanceCounters); - - // Place the counter "in scope" meaning the task is executing right now. - counter.InScope = true; - } - - // Bump up the overall number of indents, so that anything within this task will show up - // indented. - this.currentIndentLevel++; - } - - /// - /// Handler for task finished events - /// - /// sender (should be null) - /// event arguments - public override void TaskFinishedHandler(object sender, TaskFinishedEventArgs e) - { - // Done with the task, so shift everything left again. - this.currentIndentLevel--; - - if (this.showPerfSummary) - { - PerformanceCounter counter = GetPerformanceCounter(e.TaskName, ref taskPerformanceCounters); - - // Place the counter "in scope" meaning the task is done executing. - counter.InScope = false; - } - - // if verbosity is detailed or diagnostic - if (IsVerbosityAtLeast(LoggerVerbosity.Detailed)) - { - setColor(ConsoleColor.Cyan); - WriteLinePretty(e.Message); - resetColor(); - } - } - - /// - /// Prints an error event - /// - public override void ErrorHandler(object sender, BuildErrorEventArgs e) - { - errorCount++; - SetErrorsOrWarningsOnCurrentFrame(); - ShowDeferredMessages(); - setColor(ConsoleColor.Red); - WriteLinePretty(EventArgsFormatting.FormatEventMessage(e, showProjectFile)); - if (ShowSummary == true) - { - errorList.Add(e); - } - resetColor(); - } - - /// - /// Prints a warning event - /// - public override void WarningHandler(object sender, BuildWarningEventArgs e) - { - warningCount++; - SetErrorsOrWarningsOnCurrentFrame(); - ShowDeferredMessages(); - setColor(ConsoleColor.Yellow); - WriteLinePretty(EventArgsFormatting.FormatEventMessage(e, showProjectFile)); - if (ShowSummary == true) - { - warningList.Add(e); - } - resetColor(); - } - - /// - /// Prints a message event - /// - public override void MessageHandler(object sender, BuildMessageEventArgs e) - { - LoggerVerbosity minimumVerbosity = ImportanceToMinimumVerbosity(e.Importance, out bool lightenText); - bool print = IsVerbosityAtLeast(minimumVerbosity); - - if (print) - { - ShowDeferredMessages(); - - if (lightenText) - { - setColor(ConsoleColor.DarkGray); - } - - string nonNullMessage = e is EnvironmentVariableReadEventArgs environmentDerivedProperty - ? ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("EnvironmentDerivedPropertyRead", environmentDerivedProperty.EnvironmentVariableName, e.Message) - : e.Message ?? String.Empty; - - // Include file information if present. - if (e.File != null) - { - nonNullMessage = EventArgsFormatting.FormatEventMessage(e, showProjectFile); - } - - WriteLinePretty(nonNullMessage); - - if (lightenText) - { - resetColor(); - } - } - } - - /// - /// Prints a custom event - /// - public override void CustomEventHandler(object sender, CustomBuildEventArgs e) - { - // if verbosity is detailed or diagnostic - if (IsVerbosityAtLeast(LoggerVerbosity.Detailed)) - { - // ignore custom events with null messages -- some other - // logger will handle them appropriately - if (e.Message != null) - { - ShowDeferredMessages(); - WriteLinePretty(e.Message); - } - } - } - - public override void StatusEventHandler(object sender, BuildStatusEventArgs e) - { - if (e is ProjectEvaluationStartedEventArgs projectEvaluationStarted) - { - if (showPerfSummary) - { - PerformanceCounter counter = GetPerformanceCounter(projectEvaluationStarted.ProjectFile, ref projectEvaluationPerformanceCounters); - counter.InScope = true; - } - } - else if (e is ProjectEvaluationFinishedEventArgs projectEvaluationFinished) - { - if (showPerfSummary) - { - PerformanceCounter counter = GetPerformanceCounter(projectEvaluationFinished.ProjectFile, ref projectEvaluationPerformanceCounters); - counter.InScope = false; - } - - if (Verbosity == LoggerVerbosity.Diagnostic && showItemAndPropertyList) - { - if (projectEvaluationFinished.Properties != null) - { - var propertyList = ExtractPropertyList(projectEvaluationFinished.Properties); - WriteProperties(propertyList); - } - - if (projectEvaluationFinished.Items != null) - { - SortedList itemList = ExtractItemList(projectEvaluationFinished.Items); - WriteItems(itemList); - } - } - } - else if (e is BuildCanceledEventArgs buildCanceled) - { - Console.WriteLine(e.Message); - } - } - - /// - /// Writes project started messages. - /// - internal void WriteProjectStarted() - { - this.VerifyStack(!contextStack.IsEmpty(), "Bad project stack"); - - // Pop the current project - Frame outerMost = contextStack.Pop(); - - this.VerifyStack(!outerMost.displayed, "Bad project stack on {0}", outerMost.ID); - this.VerifyStack(outerMost.type == FrameType.Project, "Bad project stack"); - - outerMost.displayed = true; - contextStack.Push(outerMost); - - WriteProjectStartedText(outerMost.ID, outerMost.targetNames, outerMost.parentProjectFile, - this.IsVerbosityAtLeast(LoggerVerbosity.Normal) ? outerMost.indentLevel : 0); - } - - /// - /// Displays the text for a project started message. - /// - /// current project file - /// previous project file - /// targets that are being invoked - /// indentation level - private void WriteProjectStartedText(string current, string targetNames, string previous, int indentLevel) - { - if (!SkipProjectStartedText) - { - setColor(ConsoleColor.Cyan); - - this.VerifyStack(current != null, "Unexpected null project stack"); - - WriteLinePretty(projectSeparatorLine); - - if (previous == null) - { - if (string.IsNullOrEmpty(targetNames)) - { - WriteLinePrettyFromResource(indentLevel, "ProjectStartedPrefixForTopLevelProjectWithDefaultTargets", current); - } - else - { - WriteLinePrettyFromResource(indentLevel, "ProjectStartedPrefixForTopLevelProjectWithTargetNames", current, targetNames); - } - } - else - { - if (string.IsNullOrEmpty(targetNames)) - { - WriteLinePrettyFromResource(indentLevel, "ProjectStartedPrefixForNestedProjectWithDefaultTargets", previous, current); - } - else - { - WriteLinePrettyFromResource(indentLevel, "ProjectStartedPrefixForNestedProjectWithTargetNames", previous, current, targetNames); - } - } - - // add a little bit of extra space - WriteNewLine(); - - resetColor(); - } - } - - /// - /// Writes target started messages. - /// - private void WriteTargetStarted() - { - Frame f = contextStack.Pop(); - f.displayed = true; - contextStack.Push(f); - - setColor(ConsoleColor.Cyan); - - if (this.Verbosity == LoggerVerbosity.Diagnostic) - { - WriteLinePrettyFromResource(f.indentLevel, "TargetStartedFromFile", f.ID, f.file); - } - else - { - WriteLinePrettyFromResource(this.IsVerbosityAtLeast(LoggerVerbosity.Normal) ? f.indentLevel : 0, - "TargetStartedPrefix", f.ID); - } - - resetColor(); - } - - /// - /// Determines the currently building project file. - /// - /// name of project file currently being built - private string GetCurrentlyBuildingProjectFile() - { - if (contextStack.IsEmpty()) - { - return null; - } - - Frame topOfStack = contextStack.Peek(); - - // If the top of the stack is a TargetStarted event, then its parent project - // file is the one we want. - if (topOfStack.type == FrameType.Target) - { - return topOfStack.parentProjectFile; - } - // If the top of the stack is a ProjectStarted event, then its ID is the project - // file we want. - else if (topOfStack.type == FrameType.Project) - { - return topOfStack.ID; - } - else - { - ErrorUtilities.ThrowInternalError("Unexpected frame type."); - return null; - } - } - - /// - /// Displays project started and target started messages that - /// are shown only when the associated project or target produces - /// output. - /// - private void ShowDeferredMessages() - { - if (contextStack.IsEmpty()) - { - return; - } - - if (!contextStack.Peek().displayed) - { - Frame f = contextStack.Pop(); - - ShowDeferredMessages(); - - // push now, so that the stack is in a good state - // for WriteProjectStarted() and WriteLinePretty() - // because we use the stack to control indenting - contextStack.Push(f); - - switch (f.type) - { - case FrameType.Project: - WriteProjectStarted(); - break; - - case FrameType.Target: - // Only do things if we're at normal verbosity. If - // we're at a higher verbosity, we can assume that all - // targets have already be printed. If we're at lower - // verbosity we don't need to print at all. - ErrorUtilities.VerifyThrow(this.Verbosity < LoggerVerbosity.Detailed, - "This target should have already been printed at a higher verbosity."); - - if (IsVerbosityAtLeast(LoggerVerbosity.Normal)) - { - WriteTargetStarted(); - } - - break; - - default: - ErrorUtilities.ThrowInternalError("Unexpected frame type."); - break; - } - } - } - - /// - /// Marks the current frame to indicate that an error or warning - /// occurred during it. - /// - private void SetErrorsOrWarningsOnCurrentFrame() - { - // under unit test, there may not be frames on the stack - if (contextStack.Count == 0) - { - return; - } - - Frame frame = contextStack.Pop(); - frame.hasErrorsOrWarnings = true; - contextStack.Push(frame); - } - - /// - /// Checks the condition passed in. If it's false, it emits an error message to the console - /// indicating that there's a problem with the console logger. These "problems" should - /// never occur in the real world after we ship, unless there's a bug in the MSBuild - /// engine such that events aren't getting paired up properly. So the messages don't - /// really need to be localized here, since they're only for our own benefit, and have - /// zero value to a customer. - /// - /// - /// - /// - private void VerifyStack( - bool condition, - string unformattedMessage, - params object[] args) - { - if (!condition && !ignoreLoggerErrors) - { - string errorMessage = "INTERNAL CONSOLE LOGGER ERROR. " + ResourceUtilities.FormatString(unformattedMessage, args); - ErrorUtilities.ThrowInternalError(errorMessage); - } - } - #endregion - - #region Supporting classes - - /// - /// This enumeration represents the kinds of context that can be - /// stored in the context stack. - /// - internal enum FrameType - { - Project, - Target - } - - /// - /// This struct represents context information about a single - /// target or project. - /// - internal struct Frame - { - /// - /// Initializes a new instance of the struct with all fields specified. - /// - /// the type of the this frame - /// display state. true indicates this frame has been displayed to the user - /// indentation level for this frame - /// frame id - /// targets to execute, in the case of a project frame - /// the file name where the target is defined - /// parent project file - internal Frame( - FrameType t, - bool d, - int indent, - string s, - string targets, - string fileOfTarget, - string parent) - { - type = t; - displayed = d; - indentLevel = indent; - ID = s; - targetNames = targets; - file = fileOfTarget; - hasErrorsOrWarnings = false; - parentProjectFile = parent; - } - - /// - /// Indicates if project or target frame. - /// - internal FrameType type; - - /// - /// Set to true to indicate the user has seen a message about this frame. - /// - internal bool displayed; - - /// - /// The number of tabstops to indent this event when it is eventually displayed. - /// - internal int indentLevel; - - /// - /// A string associated with this frame -- should be a target name - /// or a project file. - /// - internal string ID; - - /// - /// For a TargetStarted or a ProjectStarted event, this field tells us - /// the name of the *parent* project file that was responsible. - /// - internal string parentProjectFile; - - /// - /// Stores the TargetNames from the ProjectStarted event. Null for Target frames. - /// - internal string targetNames; - - /// - /// For TargetStarted events, this stores the filename where the Target is defined - /// (e.g., Microsoft.Common.targets). This is different than the project that is - /// being built. - /// For ProjectStarted events, this is null. - /// - internal string file; - - /// - /// True if there were errors/warnings during the project or target frame. - /// - internal bool hasErrorsOrWarnings; - } - - /// - /// The FrameStack class represents a (lifo) stack of Frames. - /// - internal class FrameStack - { - /// - /// The frames member is contained by FrameStack and does - /// all the heavy lifting for FrameStack. - /// - private readonly Stack _frames; - - /// - /// Initializes a new instance of the class. - /// - internal FrameStack() - { - _frames = new Stack(); - } - - /// - /// Remove and return the top element in the stack. - /// - /// Thrown when stack is empty. - internal Frame Pop() - { - return _frames.Pop(); - } - - /// - /// Returns, but does not remove, the top of the stack. - /// - internal Frame Peek() - { - return _frames.Peek(); - } - - /// - /// Push(f) adds f to the top of the stack. - /// - /// a frame to push - internal void Push(Frame f) - { - _frames.Push(f); - } - - /// - /// Constant property that indicates the number of elements - /// in the stack. - /// - internal int Count - { - get - { - return _frames.Count; - } - } - - /// - /// s.IsEmpty() is true iff s.Count == 0 - /// - internal bool IsEmpty() - { - return _frames.Count == 0; - } - } - #endregion - - #region Private member data - - /// - /// contextStack is the only interesting state in the console - /// logger. The context stack contains a sequence of frames - /// denoting current and previous containing projects and targets - /// - internal FrameStack contextStack = new FrameStack(); - #endregion - } -} diff --git a/src/Build/Microsoft.Build.csproj b/src/Build/Microsoft.Build.csproj index 603b9713b1a..c2611f45952 100644 --- a/src/Build/Microsoft.Build.csproj +++ b/src/Build/Microsoft.Build.csproj @@ -572,7 +572,6 @@ - diff --git a/src/MSBuild/Resources/Strings.resx b/src/MSBuild/Resources/Strings.resx index 616aeae6f35..ffbd625bc17 100644 --- a/src/MSBuild/Resources/Strings.resx +++ b/src/MSBuild/Resources/Strings.resx @@ -371,9 +371,6 @@ the console buffer DisableConsoleColor--Use the default console colors for all logging messages. - DisableMPLogging-- Disable the multiprocessor - logging style of output when running in - non-multiprocessor mode. EnableMPLogging--Enable the multiprocessor logging style even when running in non-multiprocessor mode. This logging style is on by default. diff --git a/src/MSBuild/Resources/xlf/Strings.cs.xlf b/src/MSBuild/Resources/xlf/Strings.cs.xlf index 855757bf6ef..fa59bd91f34 100644 --- a/src/MSBuild/Resources/xlf/Strings.cs.xlf +++ b/src/MSBuild/Resources/xlf/Strings.cs.xlf @@ -844,9 +844,6 @@ Když se nastaví na MessageUponIsolationViolation (nebo jeho krátký the console buffer DisableConsoleColor--Use the default console colors for all logging messages. - DisableMPLogging-- Disable the multiprocessor - logging style of output when running in - non-multiprocessor mode. EnableMPLogging--Enable the multiprocessor logging style even when running in non-multiprocessor mode. This logging style is on by default. @@ -860,7 +857,7 @@ Když se nastaví na MessageUponIsolationViolation (nebo jeho krátký -consoleLoggerParameters:PerformanceSummary;NoSummary; Verbosity=minimal - -consoleloggerparameters:<parameters> + -consoleloggerparameters:<parameters> Parametry do protokolovacího nástroje konzoly. (Krátký tvar: -clp) Dostupné parametry jsou: PerformanceSummary – zobrazí dobu zpracování úloh, cílů diff --git a/src/MSBuild/Resources/xlf/Strings.de.xlf b/src/MSBuild/Resources/xlf/Strings.de.xlf index c25e31e3464..3be5d94e643 100644 --- a/src/MSBuild/Resources/xlf/Strings.de.xlf +++ b/src/MSBuild/Resources/xlf/Strings.de.xlf @@ -837,9 +837,6 @@ Hinweis: Ausführlichkeit der Dateiprotokollierungen the console buffer DisableConsoleColor--Use the default console colors for all logging messages. - DisableMPLogging-- Disable the multiprocessor - logging style of output when running in - non-multiprocessor mode. EnableMPLogging--Enable the multiprocessor logging style even when running in non-multiprocessor mode. This logging style is on by default. @@ -853,7 +850,7 @@ Hinweis: Ausführlichkeit der Dateiprotokollierungen -consoleLoggerParameters:PerformanceSummary;NoSummary; Verbosity=minimal - -consoleloggerparameters:<Parameter> + -consoleloggerparameters:<Parameter> Parameter für die Konsolenprotokollierung. (Kurzform: -clp) Folgende Parameter sind verfügbar: PerformanceSummary: Zeigt die in Aufgaben, Zielen und diff --git a/src/MSBuild/Resources/xlf/Strings.es.xlf b/src/MSBuild/Resources/xlf/Strings.es.xlf index b3549a9d09e..6ec09011988 100644 --- a/src/MSBuild/Resources/xlf/Strings.es.xlf +++ b/src/MSBuild/Resources/xlf/Strings.es.xlf @@ -840,9 +840,6 @@ Esta marca es experimental y puede que no funcione según lo previsto. the console buffer DisableConsoleColor--Use the default console colors for all logging messages. - DisableMPLogging-- Disable the multiprocessor - logging style of output when running in - non-multiprocessor mode. EnableMPLogging--Enable the multiprocessor logging style even when running in non-multiprocessor mode. This logging style is on by default. @@ -856,7 +853,7 @@ Esta marca es experimental y puede que no funcione según lo previsto. -consoleLoggerParameters:PerformanceSummary;NoSummary; Verbosity=minimal - -consoleLoggerParameters:<parameters> + -consoleLoggerParameters:<parameters> Parámetros del registrador de consola. (Forma corta: -clp) Los parámetros disponibles son: PerformanceSummary: muestra el tiempo empleado en tareas, destinos diff --git a/src/MSBuild/Resources/xlf/Strings.fr.xlf b/src/MSBuild/Resources/xlf/Strings.fr.xlf index 691617d0d91..76a15016ce7 100644 --- a/src/MSBuild/Resources/xlf/Strings.fr.xlf +++ b/src/MSBuild/Resources/xlf/Strings.fr.xlf @@ -837,9 +837,6 @@ Remarque : verbosité des enregistreurs d’événements de fichiers the console buffer DisableConsoleColor--Use the default console colors for all logging messages. - DisableMPLogging-- Disable the multiprocessor - logging style of output when running in - non-multiprocessor mode. EnableMPLogging--Enable the multiprocessor logging style even when running in non-multiprocessor mode. This logging style is on by default. @@ -853,7 +850,7 @@ Remarque : verbosité des enregistreurs d’événements de fichiers -consoleLoggerParameters:PerformanceSummary;NoSummary; Verbosity=minimal - -consoleLoggerParameters:<paramètres> + -consoleLoggerParameters:<paramètres> Paramètres du journaliseur de la console. (Forme abrégée : -clp) Paramètres disponibles : PerformanceSummary--Affiche la durée des tâches, des cibles diff --git a/src/MSBuild/Resources/xlf/Strings.it.xlf b/src/MSBuild/Resources/xlf/Strings.it.xlf index 3fa14d237bc..07f8b5bf112 100644 --- a/src/MSBuild/Resources/xlf/Strings.it.xlf +++ b/src/MSBuild/Resources/xlf/Strings.it.xlf @@ -844,9 +844,6 @@ Nota: livello di dettaglio dei logger di file the console buffer DisableConsoleColor--Use the default console colors for all logging messages. - DisableMPLogging-- Disable the multiprocessor - logging style of output when running in - non-multiprocessor mode. EnableMPLogging--Enable the multiprocessor logging style even when running in non-multiprocessor mode. This logging style is on by default. @@ -860,7 +857,7 @@ Nota: livello di dettaglio dei logger di file -consoleLoggerParameters:PerformanceSummary;NoSummary; Verbosity=minimal - -consoleLoggerParameters:<parameters> + -consoleLoggerParameters:<parameters> Parametri per il logger di console. (Forma breve: -clp) I parametri disponibili sono: PerformanceSummary: indica il tempo impiegato per le attività, le destinazioni diff --git a/src/MSBuild/Resources/xlf/Strings.ja.xlf b/src/MSBuild/Resources/xlf/Strings.ja.xlf index 6d6589d9ca4..0ad9788639c 100644 --- a/src/MSBuild/Resources/xlf/Strings.ja.xlf +++ b/src/MSBuild/Resources/xlf/Strings.ja.xlf @@ -837,9 +837,6 @@ the console buffer DisableConsoleColor--Use the default console colors for all logging messages. - DisableMPLogging-- Disable the multiprocessor - logging style of output when running in - non-multiprocessor mode. EnableMPLogging--Enable the multiprocessor logging style even when running in non-multiprocessor mode. This logging style is on by default. @@ -853,7 +850,7 @@ -consoleLoggerParameters:PerformanceSummary;NoSummary; Verbosity=minimal - -consoleLoggerParameters:<parameters> + -consoleLoggerParameters:<parameters> コンソール ロガーへのパラメーターです。(短縮形: -clp) 利用可能なパラメーター: PerformanceSummary--タスク、ターゲット、プロジェクトにかかった時間を diff --git a/src/MSBuild/Resources/xlf/Strings.ko.xlf b/src/MSBuild/Resources/xlf/Strings.ko.xlf index 4eca2e7f286..b50d43d9d4f 100644 --- a/src/MSBuild/Resources/xlf/Strings.ko.xlf +++ b/src/MSBuild/Resources/xlf/Strings.ko.xlf @@ -838,9 +838,6 @@ the console buffer DisableConsoleColor--Use the default console colors for all logging messages. - DisableMPLogging-- Disable the multiprocessor - logging style of output when running in - non-multiprocessor mode. EnableMPLogging--Enable the multiprocessor logging style even when running in non-multiprocessor mode. This logging style is on by default. @@ -854,7 +851,7 @@ -consoleLoggerParameters:PerformanceSummary;NoSummary; Verbosity=minimal - -consoleLoggerParameters:<parameters> + -consoleLoggerParameters:<parameters> 콘솔 로거에 대한 매개 변수입니다. (약식: -clp) 사용 가능한 매개 변수는 다음과 같습니다. PerformanceSummary--작업, 대상, 프로젝트에서 소요된 시간을 diff --git a/src/MSBuild/Resources/xlf/Strings.pl.xlf b/src/MSBuild/Resources/xlf/Strings.pl.xlf index c84a75f2ca5..dbdcdef1807 100644 --- a/src/MSBuild/Resources/xlf/Strings.pl.xlf +++ b/src/MSBuild/Resources/xlf/Strings.pl.xlf @@ -844,9 +844,6 @@ Ta flaga jest eksperymentalna i może nie działać zgodnie z oczekiwaniami. the console buffer DisableConsoleColor--Use the default console colors for all logging messages. - DisableMPLogging-- Disable the multiprocessor - logging style of output when running in - non-multiprocessor mode. EnableMPLogging--Enable the multiprocessor logging style even when running in non-multiprocessor mode. This logging style is on by default. @@ -860,7 +857,7 @@ Ta flaga jest eksperymentalna i może nie działać zgodnie z oczekiwaniami. -consoleLoggerParameters:PerformanceSummary;NoSummary; Verbosity=minimal - -consoleLoggerParameters:<parameters> + -consoleLoggerParameters:<parameters> Parametry rejestratora konsoli. (Krótka wersja: -clp) Dostępne parametry: PerformanceSummary--pokazuje czas spędzony na zadaniach, elementach docelowych diff --git a/src/MSBuild/Resources/xlf/Strings.pt-BR.xlf b/src/MSBuild/Resources/xlf/Strings.pt-BR.xlf index 828ff9e99cd..ced016e5e0e 100644 --- a/src/MSBuild/Resources/xlf/Strings.pt-BR.xlf +++ b/src/MSBuild/Resources/xlf/Strings.pt-BR.xlf @@ -837,9 +837,6 @@ arquivo de resposta. the console buffer DisableConsoleColor--Use the default console colors for all logging messages. - DisableMPLogging-- Disable the multiprocessor - logging style of output when running in - non-multiprocessor mode. EnableMPLogging--Enable the multiprocessor logging style even when running in non-multiprocessor mode. This logging style is on by default. @@ -853,7 +850,7 @@ arquivo de resposta. -consoleLoggerParameters:PerformanceSummary;NoSummary; Verbosity=minimal - -consoleLoggerParameters:<parameters> + -consoleLoggerParameters:<parameters> Parâmetros para o logger do console. (forma abreviada: -clp) Os parâmetros disponíveis são: PerformanceSummary--Mostra o tempo gasto em tarefas, alvos diff --git a/src/MSBuild/Resources/xlf/Strings.ru.xlf b/src/MSBuild/Resources/xlf/Strings.ru.xlf index 97ebb07295f..edba36acaf9 100644 --- a/src/MSBuild/Resources/xlf/Strings.ru.xlf +++ b/src/MSBuild/Resources/xlf/Strings.ru.xlf @@ -835,9 +835,6 @@ the console buffer DisableConsoleColor--Use the default console colors for all logging messages. - DisableMPLogging-- Disable the multiprocessor - logging style of output when running in - non-multiprocessor mode. EnableMPLogging--Enable the multiprocessor logging style even when running in non-multiprocessor mode. This logging style is on by default. @@ -851,7 +848,7 @@ -consoleLoggerParameters:PerformanceSummary;NoSummary; Verbosity=minimal - -consoleLoggerParameters:<параметры> + -consoleLoggerParameters:<параметры> Параметры средства ведения журнала консоли. (Краткая форма: -clp) Доступны следующие параметры: PerformanceSummary--показывать время, затраченное на выполнение задач, diff --git a/src/MSBuild/Resources/xlf/Strings.tr.xlf b/src/MSBuild/Resources/xlf/Strings.tr.xlf index e260c8b680c..f7b60c8abc1 100644 --- a/src/MSBuild/Resources/xlf/Strings.tr.xlf +++ b/src/MSBuild/Resources/xlf/Strings.tr.xlf @@ -836,9 +836,6 @@ the console buffer DisableConsoleColor--Use the default console colors for all logging messages. - DisableMPLogging-- Disable the multiprocessor - logging style of output when running in - non-multiprocessor mode. EnableMPLogging--Enable the multiprocessor logging style even when running in non-multiprocessor mode. This logging style is on by default. @@ -852,7 +849,7 @@ -consoleLoggerParameters:PerformanceSummary;NoSummary; Verbosity=minimal - -consoleLoggerParameters:<parameters> + -consoleLoggerParameters:<parameters> Konsol günlüğü için parametreler. (Kısa form: -clp) Mevcut parametreler: PerformanceSummary--Görevlerde, hedeflerde harcanan zamanı göster diff --git a/src/MSBuild/Resources/xlf/Strings.zh-Hans.xlf b/src/MSBuild/Resources/xlf/Strings.zh-Hans.xlf index 932938847c5..978706b4d4f 100644 --- a/src/MSBuild/Resources/xlf/Strings.zh-Hans.xlf +++ b/src/MSBuild/Resources/xlf/Strings.zh-Hans.xlf @@ -836,9 +836,6 @@ the console buffer DisableConsoleColor--Use the default console colors for all logging messages. - DisableMPLogging-- Disable the multiprocessor - logging style of output when running in - non-multiprocessor mode. EnableMPLogging--Enable the multiprocessor logging style even when running in non-multiprocessor mode. This logging style is on by default. @@ -852,7 +849,7 @@ -consoleLoggerParameters:PerformanceSummary;NoSummary; Verbosity=minimal - -consoleloggerparameters:<parameters> + -consoleloggerparameters:<parameters> 控制台记录器的参数。(缩写: -clp) 可用参数包括: PerformanceSummary -- 显示在任务、目标和项目上 diff --git a/src/MSBuild/Resources/xlf/Strings.zh-Hant.xlf b/src/MSBuild/Resources/xlf/Strings.zh-Hant.xlf index 181ec74db57..10bcf292ae7 100644 --- a/src/MSBuild/Resources/xlf/Strings.zh-Hant.xlf +++ b/src/MSBuild/Resources/xlf/Strings.zh-Hant.xlf @@ -837,9 +837,6 @@ the console buffer DisableConsoleColor--Use the default console colors for all logging messages. - DisableMPLogging-- Disable the multiprocessor - logging style of output when running in - non-multiprocessor mode. EnableMPLogging--Enable the multiprocessor logging style even when running in non-multiprocessor mode. This logging style is on by default. @@ -853,7 +850,7 @@ -consoleLoggerParameters:PerformanceSummary;NoSummary; Verbosity=minimal - -consoleLoggerParameters:<parameters> + -consoleLoggerParameters:<parameters> 主控台記錄器的參數。(簡短形式: -clp) 可用的參數為: PerformanceSummary--顯示工作、目標 diff --git a/src/MSBuild/XMake.cs b/src/MSBuild/XMake.cs index 7baa19e1cc4..c36a0cabf52 100644 --- a/src/MSBuild/XMake.cs +++ b/src/MSBuild/XMake.cs @@ -1361,7 +1361,6 @@ internal static bool BuildProject( verbosity == LoggerVerbosity.Quiet && loggers[0].Parameters != null && loggers[0].Parameters.IndexOf("ENABLEMPLOGGING", StringComparison.OrdinalIgnoreCase) != -1 && - loggers[0].Parameters.IndexOf("DISABLEMPLOGGING", StringComparison.OrdinalIgnoreCase) == -1 && loggers[0].Parameters.IndexOf("V=", StringComparison.OrdinalIgnoreCase) == -1 && // Console logger could have had a verbosity loggers[0].Parameters.IndexOf("VERBOSITY=", StringComparison.OrdinalIgnoreCase) == -1) // override with the /clp switch { diff --git a/src/UnitTests.Shared/EngineTestEnvironment.cs b/src/UnitTests.Shared/EngineTestEnvironment.cs index 6464653bcf9..b63d7b2ee91 100644 --- a/src/UnitTests.Shared/EngineTestEnvironment.cs +++ b/src/UnitTests.Shared/EngineTestEnvironment.cs @@ -159,7 +159,6 @@ public override void Revert() result.Add(GetMockLogger()); #if MICROSOFT_BUILD_ENGINE_UNITTESTS - result.Add(GetSerialLogger()); result.Add(GetParallelLogger()); #endif @@ -174,14 +173,6 @@ public override void Revert() #if MICROSOFT_BUILD_ENGINE_UNITTESTS - private (ILogger, Func) GetSerialLogger() - { - var sb = new StringBuilder(); - var serialFromBuild = new SerialConsoleLogger(LoggerVerbosity.Diagnostic, t => sb.Append(t), colorSet: null, colorReset: null); - serialFromBuild.Parameters = "NOPERFORMANCESUMMARY"; - return (serialFromBuild, () => sb.ToString()); - } - private (ILogger, Func) GetParallelLogger() { var sb = new StringBuilder(); From 3e7c9340c5aa61f1ecd24d2939424640595049d6 Mon Sep 17 00:00:00 2001 From: YuliiaKovalova Date: Wed, 13 Aug 2025 17:08:11 +0200 Subject: [PATCH 2/4] fix tests --- .../LoggingConfigurationTelemetry_Tests.cs | 12 +- src/Build.UnitTests/BinaryLogger_Tests.cs | 2 +- src/Build.UnitTests/ConsoleLogger_Tests.cs | 1188 ++++++----------- src/Build.UnitTests/FileLogger_Tests.cs | 23 +- .../TerminalLoggerConfiguration_Tests.cs | 2 - src/Build/Logging/ConsoleLogger.cs | 9 +- src/Build/Logging/FileLogger.cs | 1 - .../LoggingConfigurationTelemetry.cs | 25 - src/MSBuild/XMake.cs | 2 - 9 files changed, 450 insertions(+), 814 deletions(-) diff --git a/src/Build.UnitTests/BackEnd/LoggingConfigurationTelemetry_Tests.cs b/src/Build.UnitTests/BackEnd/LoggingConfigurationTelemetry_Tests.cs index 56ec028ddf1..ef4faec0b34 100644 --- a/src/Build.UnitTests/BackEnd/LoggingConfigurationTelemetry_Tests.cs +++ b/src/Build.UnitTests/BackEnd/LoggingConfigurationTelemetry_Tests.cs @@ -29,16 +29,16 @@ public void BuildTelemetryConstructedHasNoProperties() telemetry.TerminalLoggerDefault.ShouldBeNull(); telemetry.TerminalLoggerDefaultSource.ShouldBeNull(); telemetry.ConsoleLogger.ShouldBe(false); - telemetry.ConsoleLoggerType.ShouldBeNull(); telemetry.ConsoleLoggerVerbosity.ShouldBeNull(); telemetry.FileLogger.ShouldBe(false); telemetry.FileLoggerVerbosity.ShouldBeNull(); - telemetry.FileLoggersCount.ShouldBe(0); telemetry.FileLoggerVerbosity.ShouldBeNull(); telemetry.BinaryLogger.ShouldBe(false); telemetry.BinaryLoggerUsedDefaultName.ShouldBe(false); - telemetry.GetProperties().Where(kv => kv.Value != bool.FalseString).ShouldBeEmpty(); + telemetry.GetProperties() + .Where(kv => kv.Value != bool.FalseString) + .ShouldBeEmpty(); } [Fact] @@ -52,11 +52,8 @@ public void BuildTelemetryCreateProperProperties() TerminalLoggerDefault = "auto", TerminalLoggerDefaultSource = "sdk", ConsoleLogger = true, - ConsoleLoggerType = "serial", ConsoleLoggerVerbosity = "minimal", FileLogger = true, - FileLoggerType = "serial", - FileLoggersCount = 2, FileLoggerVerbosity = "normal", BinaryLogger = true, BinaryLoggerUsedDefaultName = true @@ -69,11 +66,8 @@ public void BuildTelemetryCreateProperProperties() properties["TerminalLoggerDefault"].ShouldBe("auto"); properties["TerminalLoggerDefaultSource"].ShouldBe("sdk"); properties["ConsoleLogger"].ShouldBe(bool.TrueString); - properties["ConsoleLoggerType"].ShouldBe("serial"); properties["ConsoleLoggerVerbosity"].ShouldBe("minimal"); properties["FileLogger"].ShouldBe(bool.TrueString); - properties["FileLoggerType"].ShouldBe("serial"); - properties["FileLoggersCount"].ShouldBe("2"); properties["FileLoggerVerbosity"].ShouldBe("normal"); properties["BinaryLogger"].ShouldBe(bool.TrueString); properties["BinaryLoggerUsedDefaultName"].ShouldBe(bool.TrueString); diff --git a/src/Build.UnitTests/BinaryLogger_Tests.cs b/src/Build.UnitTests/BinaryLogger_Tests.cs index 09f6c8bf529..97fe6342c62 100644 --- a/src/Build.UnitTests/BinaryLogger_Tests.cs +++ b/src/Build.UnitTests/BinaryLogger_Tests.cs @@ -112,7 +112,7 @@ public void TestBinaryLoggerRoundtrip(string projectText, BinlogRoundtripTestRep var parallelFromBuild = new ParallelConsoleLogger(Framework.LoggerVerbosity.Diagnostic, t => parallelFromBuildText.Append(t), colorSet: null, colorReset: null); parallelFromBuild.Parameters = "NOPERFORMANCESUMMARY"; - // build and log into binary logger, mock logger, serial and parallel console loggers + // build and log into binary logger, mock logger and parallel console loggers // no logging on evaluation using (ProjectCollection collection = new()) { diff --git a/src/Build.UnitTests/ConsoleLogger_Tests.cs b/src/Build.UnitTests/ConsoleLogger_Tests.cs index c1dec84bb6e..139e461cc40 100644 --- a/src/Build.UnitTests/ConsoleLogger_Tests.cs +++ b/src/Build.UnitTests/ConsoleLogger_Tests.cs @@ -452,27 +452,25 @@ public void NullEventFields() { EventSourceSink es = new EventSourceSink(); SimulatedConsole sc = new SimulatedConsole(); - ConsoleLogger L = new ConsoleLogger(LoggerVerbosity.Diagnostic, - sc.Write, sc.SetColor, - sc.ResetColor); + ConsoleLogger L = new ConsoleLogger(LoggerVerbosity.Diagnostic, sc.Write, sc.SetColor, sc.ResetColor); L.Initialize(es); // Not all parameters are null here, but that's fine, we assume the engine will never // fire a ProjectStarted without a project name, etc. es.Consume(new BuildStartedEventArgs(null, null)); - es.Consume(new ProjectStartedEventArgs(null, null, "p", null, null, null)); - es.Consume(new TargetStartedEventArgs(null, null, "t", null, null)); - es.Consume(new TaskStartedEventArgs(null, null, null, null, "task")); - es.Consume(new BuildMessageEventArgs(null, null, null, MessageImportance.High)); - es.Consume(new BuildWarningEventArgs(null, null, null, 0, 0, 0, 0, null, null, null)); - es.Consume(new BuildErrorEventArgs(null, null, null, 0, 0, 0, 0, null, null, null)); - es.Consume(new TaskFinishedEventArgs(null, null, null, null, "task", true)); - es.Consume(new TargetFinishedEventArgs(null, null, "t", null, null, true)); - es.Consume(new ProjectFinishedEventArgs(null, null, "p", true)); - es.Consume(new BuildFinishedEventArgs(null, null, true)); - es.Consume(new BuildFinishedEventArgs(null, null, true)); - es.Consume(new BuildFinishedEventArgs(null, null, true)); - es.Consume(new MyCustomBuildEventArgs2()); + es.Consume(new ProjectStartedEventArgs(1, null, null, "p", null, null, null, parentBuildEventContext: new BuildEventContext(1, 1, 1, 1)) { BuildEventContext = new BuildEventContext(1, 1, 1, 1) }); + es.Consume(new TargetStartedEventArgs(null, null, "t", null, null) { BuildEventContext = new BuildEventContext(1, 1, 1, 1) }); + es.Consume(new TaskStartedEventArgs(null, null, null, null, "task") { BuildEventContext = new BuildEventContext(1, 1, 1, 1) }); + es.Consume(new BuildMessageEventArgs(null, null, null, MessageImportance.High) { BuildEventContext = new BuildEventContext(1, 1, 1, 1) }); + es.Consume(new BuildWarningEventArgs(null, null, null, 0, 0, 0, 0, null, null, null) { BuildEventContext = new BuildEventContext(1, 1, 1, 1) }); + es.Consume(new BuildErrorEventArgs(null, null, null, 0, 0, 0, 0, null, null, null) { BuildEventContext = new BuildEventContext(1, 1, 1, 1) }); + es.Consume(new TaskFinishedEventArgs(null, null, null, null, "task", true) { BuildEventContext = new BuildEventContext(1, 1, 1, 1) }); + es.Consume(new TargetFinishedEventArgs(null, null, "t", null, null, true) { BuildEventContext = new BuildEventContext(1, 1, 1, 1) }); + es.Consume(new ProjectFinishedEventArgs(null, null, "p", true) { BuildEventContext = new BuildEventContext(1, 1, 1, 1) }); + es.Consume(new BuildFinishedEventArgs(null, null, true) { BuildEventContext = new BuildEventContext(1, 1, 1, 1) }); + es.Consume(new BuildFinishedEventArgs(null, null, true) { BuildEventContext = new BuildEventContext(1, 1, 1, 1) }); + es.Consume(new BuildFinishedEventArgs(null, null, true) { BuildEventContext = new BuildEventContext(1, 1, 1, 1) }); + es.Consume(new MyCustomBuildEventArgs2() { BuildEventContext = new BuildEventContext(1, 1, 1, 1) }); // No exception raised } @@ -593,56 +591,40 @@ public void TestVerbosityLessThan(LoggerVerbosity loggerVerbosity, LoggerVerbosi [Theory] public void SingleMessageTest(LoggerVerbosity loggerVerbosity, MessageImportance messageImportance, bool shouldPrint) { - for (int i = 1; i <= 2; i++) - { - string message = "my 1337 message"; + string message = "my 1337 message"; - SimulatedConsole console = new SimulatedConsole(); - EventSourceSink eventSourceSink = new EventSourceSink(); - ConsoleLogger logger = new ConsoleLogger(loggerVerbosity, console.Write, null, null); - logger.Initialize(eventSourceSink, i); + SimulatedConsole console = new SimulatedConsole(); + EventSourceSink eventSourceSink = new EventSourceSink(); + ConsoleLogger logger = new ConsoleLogger(loggerVerbosity, console.Write, null, null); + logger.Initialize(eventSourceSink); - BuildMessageEventArgs be = new BuildMessageEventArgs(message, "help", "sender", messageImportance) - { - BuildEventContext = new BuildEventContext(1, 2, 3, 4) - }; + BuildMessageEventArgs be = new BuildMessageEventArgs(message, "help", "sender", messageImportance) + { + BuildEventContext = new BuildEventContext(1, 2, 3, 4) + }; - eventSourceSink.Consume(be); + eventSourceSink.Consume(be); - if (i == 2 && loggerVerbosity == LoggerVerbosity.Diagnostic) - { - string context = ResourceUtilities.FormatResourceStringStripCodeAndKeyword("BuildEventContext", LogFormatter.FormatLogTimeStamp(be.Timestamp), 0) + ">"; - message = context + ResourceUtilities.FormatResourceStringStripCodeAndKeyword("TaskMessageWithId", "my 1337 message", be.BuildEventContext.TaskId); - } - else if (i == 2 && loggerVerbosity == LoggerVerbosity.Detailed) - { - string context = ResourceUtilities.FormatResourceStringStripCodeAndKeyword("BuildEventContext", string.Empty, 0) + ">"; - message = context + "my 1337 message"; - } - else if (i == 2) - { - message = " " + message; - } + if (loggerVerbosity == LoggerVerbosity.Diagnostic) + { + message = ResourceUtilities.FormatResourceStringStripCodeAndKeyword("TaskMessageWithId", "my 1337 message", be.BuildEventContext.TaskId); + } - if (shouldPrint) - { - console.ToString().ShouldBe(message + Environment.NewLine); - } - else - { - console.ToString().ShouldBeEmpty(); - } + if (shouldPrint) + { + console.ToString().ShouldContain(message + Environment.NewLine); + } + else + { + console.ToString().ShouldBeEmpty(); } } - [InlineData("error", "red", false)] - [InlineData("error", "red", true)] - [InlineData("warning", "yellow", false)] - [InlineData("warning", "yellow", true)] - [InlineData("message", "darkgray", false)] - [InlineData("message", "darkgray", true)] + [InlineData("error", "red")] + [InlineData("warning", "yellow")] + [InlineData("message", "darkgray")] [Theory] - public void ColorTest(string expectedMessageType, string expectedColor, bool parallel) + public void ColorTest(string expectedMessageType, string expectedColor) { const string subcategory = "VBC"; const string code = "31415"; @@ -680,153 +662,125 @@ public void ColorTest(string expectedMessageType, string expectedColor, bool par SimulatedConsole console = new SimulatedConsole(); ConsoleLogger logger = new ConsoleLogger(LoggerVerbosity.Diagnostic, console.Write, console.SetColor, console.ResetColor); - if (parallel) - { - logger.Initialize(eventSourceSink, 4); - eventSourceSink.Consume(buildEventArgs, 2); + logger.Initialize(eventSourceSink, 4); + eventSourceSink.Consume(buildEventArgs, 2); - if (expectedMessageType.Equals("message")) - { - console.ToString().ShouldMatch($@"<{expectedColor}>\d\d:\d\d:\d\d\.\d\d\d\s+\d+>{Regex.Escape(file)}\({lineNumber}\): {subcategory} {expectedMessageType} {code}: {message} \(TaskId:\d+\){Environment.NewLine}"); - } - else - { - console.ToString().ShouldMatch($@"\d\d:\d\d:\d\d\.\d\d\d\s+\d+><{expectedColor}>{Regex.Escape(file)}\({lineNumber}\): {subcategory} {expectedMessageType} {code}: {message}{Environment.NewLine}"); - } + if (expectedMessageType.Equals("message")) + { + console.ToString().ShouldMatch($@"<{expectedColor}>\d\d:\d\d:\d\d\.\d\d\d\s+\d+>{Regex.Escape(file)}\({lineNumber}\): {subcategory} {expectedMessageType} {code}: {message} \(TaskId:\d+\){Environment.NewLine}"); } else { - logger.Initialize(eventSourceSink); - eventSourceSink.Consume(buildEventArgs); - console.ToString().ShouldMatch($@"<{expectedColor}>{Regex.Escape(file)}\({lineNumber}\): {subcategory} {expectedMessageType} {code}: {message}{Environment.NewLine}"); + console.ToString().ShouldMatch($@"\d\d:\d\d:\d\d\.\d\d\d\s+\d+><{expectedColor}>{Regex.Escape(file)}\({lineNumber}\): {subcategory} {expectedMessageType} {code}: {message}{Environment.NewLine}"); } } - [Fact] public void TestQuietWithHighMessage() { - for (int i = 1; i <= 2; i++) - { - EventSourceSink es = new EventSourceSink(); - SimulatedConsole sc = new SimulatedConsole(); - ConsoleLogger L = new ConsoleLogger(LoggerVerbosity.Quiet, - sc.Write, sc.SetColor, - sc.ResetColor); - L.Initialize(es, i); + EventSourceSink es = new EventSourceSink(); + SimulatedConsole sc = new SimulatedConsole(); + ConsoleLogger L = new ConsoleLogger(LoggerVerbosity.Quiet, + sc.Write, sc.SetColor, + sc.ResetColor); + L.Initialize(es); - BuildEventContext buildEventContext = new BuildEventContext(1, 2, 3, 4); + BuildEventContext buildEventContext = new BuildEventContext(1, 2, 3, 4); - BuildStartedEventArgs bse = new BuildStartedEventArgs("bs", null); - bse.BuildEventContext = buildEventContext; - es.Consume(bse); + BuildStartedEventArgs bse = new BuildStartedEventArgs("bs", null); + bse.BuildEventContext = buildEventContext; + es.Consume(bse); - ProjectStartedEventArgs pse = new ProjectStartedEventArgs(1, "ps", null, "fname", "", null, null, new BuildEventContext(1, 1, 1, 1)); - pse.BuildEventContext = buildEventContext; - es.Consume(pse); + ProjectStartedEventArgs pse = new ProjectStartedEventArgs(1, "ps", null, "fname", "", null, null, new BuildEventContext(1, 1, 1, 1)); + pse.BuildEventContext = buildEventContext; + es.Consume(pse); - TargetStartedEventArgs trse = new TargetStartedEventArgs("ts", null, "trname", "pfile", "tfile"); - trse.BuildEventContext = buildEventContext; - es.Consume(trse); + TargetStartedEventArgs trse = new TargetStartedEventArgs("ts", null, "trname", "pfile", "tfile"); + trse.BuildEventContext = buildEventContext; + es.Consume(trse); - TaskStartedEventArgs tase = new TaskStartedEventArgs("tks", null, "tname", "tfname", "tsname"); - tase.BuildEventContext = buildEventContext; - es.Consume(tase); + TaskStartedEventArgs tase = new TaskStartedEventArgs("tks", null, "tname", "tfname", "tsname"); + tase.BuildEventContext = buildEventContext; + es.Consume(tase); - BuildMessageEventArgs bmea = new BuildMessageEventArgs("foo!", null, "sender", MessageImportance.High); - bmea.BuildEventContext = buildEventContext; - es.Consume(bmea); + BuildMessageEventArgs bmea = new BuildMessageEventArgs("foo!", null, "sender", MessageImportance.High); + bmea.BuildEventContext = buildEventContext; + es.Consume(bmea); - TaskFinishedEventArgs tafea = new TaskFinishedEventArgs("tkf", null, "fname", "tsname", "tfname", true); - tafea.BuildEventContext = buildEventContext; - es.Consume(tafea); + TaskFinishedEventArgs tafea = new TaskFinishedEventArgs("tkf", null, "fname", "tsname", "tfname", true); + tafea.BuildEventContext = buildEventContext; + es.Consume(tafea); - TargetFinishedEventArgs trfea = new TargetFinishedEventArgs("tf", null, "trname", "fname", "tfile", true); - trfea.BuildEventContext = buildEventContext; - es.Consume(trfea); + TargetFinishedEventArgs trfea = new TargetFinishedEventArgs("tf", null, "trname", "fname", "tfile", true); + trfea.BuildEventContext = buildEventContext; + es.Consume(trfea); - ProjectFinishedEventArgs pfea = new ProjectFinishedEventArgs("pf", null, "fname", true); - pfea.BuildEventContext = buildEventContext; - es.Consume(pfea); + ProjectFinishedEventArgs pfea = new ProjectFinishedEventArgs("pf", null, "fname", true); + pfea.BuildEventContext = buildEventContext; + es.Consume(pfea); - BuildFinishedEventArgs bfea = new BuildFinishedEventArgs("bf", null, true); - bfea.BuildEventContext = buildEventContext; - es.Consume(bfea); + BuildFinishedEventArgs bfea = new BuildFinishedEventArgs("bf", null, true); + bfea.BuildEventContext = buildEventContext; + es.Consume(bfea); - sc.ToString().ShouldBeEmpty(); - } + sc.ToString().ShouldBeEmpty(); } [Fact] public void TestQuietWithError() { - for (int i = 1; i <= 2; i++) - { - EventSourceSink es = new EventSourceSink(); - SimulatedConsole sc = new SimulatedConsole(); - ConsoleLogger L = new ConsoleLogger(LoggerVerbosity.Quiet, - sc.Write, sc.SetColor, sc.ResetColor); - L.Initialize(es, i); + EventSourceSink es = new EventSourceSink(); + SimulatedConsole sc = new SimulatedConsole(); + ConsoleLogger L = new ConsoleLogger(LoggerVerbosity.Quiet, + sc.Write, sc.SetColor, sc.ResetColor); + L.Initialize(es); - BuildEventContext buildEventContext = new BuildEventContext(1, 2, 3, 4); + BuildEventContext buildEventContext = new BuildEventContext(1, 2, 3, 4); - BuildStartedEventArgs bse = new BuildStartedEventArgs("bs", null); - bse.BuildEventContext = buildEventContext; - es.Consume(bse); + BuildStartedEventArgs bse = new BuildStartedEventArgs("bs", null); + bse.BuildEventContext = buildEventContext; + es.Consume(bse); - ProjectStartedEventArgs pse = new ProjectStartedEventArgs(-1, "ps", null, "fname", "", null, null, new BuildEventContext(1, 2, 3, 4)); - pse.BuildEventContext = buildEventContext; - es.Consume(pse); + ProjectStartedEventArgs pse = new ProjectStartedEventArgs(-1, "ps", null, "fname", "", null, null, new BuildEventContext(1, 2, 3, 4)); + pse.BuildEventContext = buildEventContext; + es.Consume(pse); - TargetStartedEventArgs trse = new TargetStartedEventArgs("ts", null, "trname", "pfile", "tfile"); - trse.BuildEventContext = buildEventContext; - es.Consume(trse); + TargetStartedEventArgs trse = new TargetStartedEventArgs("ts", null, "trname", "pfile", "tfile"); + trse.BuildEventContext = buildEventContext; + es.Consume(trse); - TaskStartedEventArgs tase = new TaskStartedEventArgs("tks", null, "tname", "tfname", "tsname"); - tase.BuildEventContext = buildEventContext; - es.Consume(tase); + TaskStartedEventArgs tase = new TaskStartedEventArgs("tks", null, "tname", "tfname", "tsname"); + tase.BuildEventContext = buildEventContext; + es.Consume(tase); - BuildErrorEventArgs beea = new BuildErrorEventArgs("VBC", - "31415", "file.vb", 42, 0, 0, 0, - "Some long message", "help", "sender"); + BuildErrorEventArgs beea = new BuildErrorEventArgs("VBC", + "31415", "file.vb", 42, 0, 0, 0, + "Some long message", "help", "sender"); - beea.BuildEventContext = buildEventContext; - es.Consume(beea); + beea.BuildEventContext = buildEventContext; + es.Consume(beea); - TaskFinishedEventArgs tafea = new TaskFinishedEventArgs("tkf", null, "fname", "tsname", "tfname", true); - tafea.BuildEventContext = buildEventContext; - es.Consume(tafea); + TaskFinishedEventArgs tafea = new TaskFinishedEventArgs("tkf", null, "fname", "tsname", "tfname", true); + tafea.BuildEventContext = buildEventContext; + es.Consume(tafea); - TargetFinishedEventArgs trfea = new TargetFinishedEventArgs("tf", null, "trname", "fname", "tfile", true); - trfea.BuildEventContext = buildEventContext; - es.Consume(trfea); + TargetFinishedEventArgs trfea = new TargetFinishedEventArgs("tf", null, "trname", "fname", "tfile", true); + trfea.BuildEventContext = buildEventContext; + es.Consume(trfea); - ProjectFinishedEventArgs pfea = new ProjectFinishedEventArgs("pf", null, "fname", true); - pfea.BuildEventContext = buildEventContext; - es.Consume(pfea); + ProjectFinishedEventArgs pfea = new ProjectFinishedEventArgs("pf", null, "fname", true); + pfea.BuildEventContext = buildEventContext; + es.Consume(pfea); - BuildFinishedEventArgs bfea = new BuildFinishedEventArgs("bf", null, true); - bfea.BuildEventContext = buildEventContext; - es.Consume(bfea); + BuildFinishedEventArgs bfea = new BuildFinishedEventArgs("bf", null, true); + bfea.BuildEventContext = buildEventContext; + es.Consume(bfea); - _output.WriteLine("=="); - _output.WriteLine(sc.ToString()); - _output.WriteLine("=="); + _output.WriteLine("=="); + _output.WriteLine(sc.ToString()); + _output.WriteLine("=="); - if (i == 1) - { - sc.ToString().ShouldBe( - "" + BaseConsoleLogger.projectSeparatorLine + Environment.NewLine + - ResourceUtilities.FormatResourceStringStripCodeAndKeyword("ProjectStartedPrefixForTopLevelProjectWithDefaultTargets", "fname") + Environment.NewLine + Environment.NewLine + - "file.vb(42): VBC error 31415: Some long message" + Environment.NewLine + - "pf" + Environment.NewLine + - ""); - } - else - { - sc.ToString().ShouldBe("file.vb(42): VBC error 31415: Some long message" + Environment.NewLine + ""); - } - } + sc.ToString().ShouldBe("file.vb(42): VBC error 31415: Some long message" + Environment.NewLine + ""); } /// @@ -836,74 +790,59 @@ public void TestQuietWithError() [Fact] public void TestQuietWithWarning() { - for (int i = 1; i <= 2; i++) - { - EventSourceSink es = new EventSourceSink(); - SimulatedConsole sc = new SimulatedConsole(); - ConsoleLogger L = new ConsoleLogger(LoggerVerbosity.Quiet, - sc.Write, sc.SetColor, sc.ResetColor); - L.Initialize(es, i); + EventSourceSink es = new EventSourceSink(); + SimulatedConsole sc = new SimulatedConsole(); + ConsoleLogger L = new ConsoleLogger(LoggerVerbosity.Quiet, + sc.Write, sc.SetColor, sc.ResetColor); + L.Initialize(es); - BuildEventContext buildEventContext = new BuildEventContext(1, 2, 3, 4); + BuildEventContext buildEventContext = new BuildEventContext(1, 2, 3, 4); - BuildStartedEventArgs bse = new BuildStartedEventArgs("bs", null); - bse.BuildEventContext = buildEventContext; - es.Consume(bse); + BuildStartedEventArgs bse = new BuildStartedEventArgs("bs", null); + bse.BuildEventContext = buildEventContext; + es.Consume(bse); - ProjectStartedEventArgs pse = new ProjectStartedEventArgs(-1, "ps", null, "fname", "", null, null, new BuildEventContext(1, 2, 3, 4)); - pse.BuildEventContext = buildEventContext; - es.Consume(pse); + ProjectStartedEventArgs pse = new ProjectStartedEventArgs(-1, "ps", null, "fname", "", null, null, new BuildEventContext(1, 2, 3, 4)); + pse.BuildEventContext = buildEventContext; + es.Consume(pse); - TargetStartedEventArgs trse = new TargetStartedEventArgs("ts", null, "trname", "pfile", "tfile"); - trse.BuildEventContext = buildEventContext; - es.Consume(trse); + TargetStartedEventArgs trse = new TargetStartedEventArgs("ts", null, "trname", "pfile", "tfile"); + trse.BuildEventContext = buildEventContext; + es.Consume(trse); - TaskStartedEventArgs tase = new TaskStartedEventArgs("tks", null, "tname", "tfname", "tsname"); - tase.BuildEventContext = buildEventContext; - es.Consume(tase); + TaskStartedEventArgs tase = new TaskStartedEventArgs("tks", null, "tname", "tfname", "tsname"); + tase.BuildEventContext = buildEventContext; + es.Consume(tase); - BuildWarningEventArgs beea = new BuildWarningEventArgs("VBC", - "31415", "file.vb", 42, 0, 0, 0, - "Some long message", "help", "sender"); + BuildWarningEventArgs beea = new BuildWarningEventArgs("VBC", + "31415", "file.vb", 42, 0, 0, 0, + "Some long message", "help", "sender"); - beea.BuildEventContext = buildEventContext; - es.Consume(beea); + beea.BuildEventContext = buildEventContext; + es.Consume(beea); - TaskFinishedEventArgs tafea = new TaskFinishedEventArgs("tkf", null, "fname", "tsname", "tfname", true); - tafea.BuildEventContext = buildEventContext; - es.Consume(tafea); + TaskFinishedEventArgs tafea = new TaskFinishedEventArgs("tkf", null, "fname", "tsname", "tfname", true); + tafea.BuildEventContext = buildEventContext; + es.Consume(tafea); - TargetFinishedEventArgs trfea = new TargetFinishedEventArgs("tf", null, "trname", "fname", "tfile", true); - trfea.BuildEventContext = buildEventContext; - es.Consume(trfea); + TargetFinishedEventArgs trfea = new TargetFinishedEventArgs("tf", null, "trname", "fname", "tfile", true); + trfea.BuildEventContext = buildEventContext; + es.Consume(trfea); - ProjectFinishedEventArgs pfea = new ProjectFinishedEventArgs("pf", null, "fname", true); - pfea.BuildEventContext = buildEventContext; - es.Consume(pfea); + ProjectFinishedEventArgs pfea = new ProjectFinishedEventArgs("pf", null, "fname", true); + pfea.BuildEventContext = buildEventContext; + es.Consume(pfea); - BuildFinishedEventArgs bfea = new BuildFinishedEventArgs("bf", null, true); - bfea.BuildEventContext = buildEventContext; - es.Consume(bfea); + BuildFinishedEventArgs bfea = new BuildFinishedEventArgs("bf", null, true); + bfea.BuildEventContext = buildEventContext; + es.Consume(bfea); - _output.WriteLine("=="); - _output.WriteLine(sc.ToString()); - _output.WriteLine("=="); + _output.WriteLine("=="); + _output.WriteLine(sc.ToString()); + _output.WriteLine("=="); - if (i == 1) - { - sc.ToString().ShouldBe( - "" + BaseConsoleLogger.projectSeparatorLine + Environment.NewLine + - ResourceUtilities.FormatResourceStringStripCodeAndKeyword("ProjectStartedPrefixForTopLevelProjectWithDefaultTargets", "fname") + Environment.NewLine + Environment.NewLine + - "file.vb(42): VBC warning 31415: Some long message" + Environment.NewLine + - "pf" + Environment.NewLine + - ""); - } - else - { - sc.ToString().ShouldBe("file.vb(42): VBC warning 31415: Some long message" + Environment.NewLine + ""); - } - } + sc.ToString().ShouldBe("file.vb(42): VBC warning 31415: Some long message" + Environment.NewLine + ""); } /// @@ -912,55 +851,52 @@ public void TestQuietWithWarning() [Fact] public void TestMinimalWithNormalMessage() { - for (int i = 1; i <= 2; i++) - { - EventSourceSink es = new EventSourceSink(); - SimulatedConsole sc = new SimulatedConsole(); - ConsoleLogger L = new ConsoleLogger(LoggerVerbosity.Minimal, - sc.Write, sc.SetColor, - sc.ResetColor); - L.Initialize(es, i); + EventSourceSink es = new EventSourceSink(); + SimulatedConsole sc = new SimulatedConsole(); + ConsoleLogger L = new ConsoleLogger(LoggerVerbosity.Minimal, + sc.Write, sc.SetColor, + sc.ResetColor); + L.Initialize(es); - BuildEventContext buildEventContext = new BuildEventContext(1, 2, 3, 4); + BuildEventContext buildEventContext = new BuildEventContext(1, 2, 3, 4); - BuildStartedEventArgs bse = new BuildStartedEventArgs("bs", null); - bse.BuildEventContext = buildEventContext; - es.Consume(bse); + BuildStartedEventArgs bse = new BuildStartedEventArgs("bs", null); + bse.BuildEventContext = buildEventContext; + es.Consume(bse); - ProjectStartedEventArgs pse = new ProjectStartedEventArgs(1, "ps", null, "fname", "", null, null, new BuildEventContext(1, 1, 1, 1)); - pse.BuildEventContext = buildEventContext; - es.Consume(pse); + ProjectStartedEventArgs pse = new ProjectStartedEventArgs(1, "ps", null, "fname", "", null, null, new BuildEventContext(1, 1, 1, 1)); + pse.BuildEventContext = buildEventContext; + es.Consume(pse); - TargetStartedEventArgs trse = new TargetStartedEventArgs("ts", null, "trname", "pfile", "tfile"); - trse.BuildEventContext = buildEventContext; - es.Consume(trse); + TargetStartedEventArgs trse = new TargetStartedEventArgs("ts", null, "trname", "pfile", "tfile"); + trse.BuildEventContext = buildEventContext; + es.Consume(trse); - TaskStartedEventArgs tase = new TaskStartedEventArgs("tks", null, "tname", "tfname", "tsname"); - tase.BuildEventContext = buildEventContext; - es.Consume(tase); + TaskStartedEventArgs tase = new TaskStartedEventArgs("tks", null, "tname", "tfname", "tsname"); + tase.BuildEventContext = buildEventContext; + es.Consume(tase); - BuildMessageEventArgs bmea = new BuildMessageEventArgs("foo!", null, "sender", MessageImportance.Normal); - bmea.BuildEventContext = buildEventContext; - es.Consume(bmea); + BuildMessageEventArgs bmea = new BuildMessageEventArgs("foo!", null, "sender", MessageImportance.Normal); + bmea.BuildEventContext = buildEventContext; + es.Consume(bmea); - TaskFinishedEventArgs tafea = new TaskFinishedEventArgs("tkf", null, "fname", "tsname", "tfname", true); - tafea.BuildEventContext = buildEventContext; - es.Consume(tafea); + TaskFinishedEventArgs tafea = new TaskFinishedEventArgs("tkf", null, "fname", "tsname", "tfname", true); + tafea.BuildEventContext = buildEventContext; + es.Consume(tafea); - TargetFinishedEventArgs trfea = new TargetFinishedEventArgs("tf", null, "trname", "fname", "tfile", true); - trfea.BuildEventContext = buildEventContext; - es.Consume(trfea); + TargetFinishedEventArgs trfea = new TargetFinishedEventArgs("tf", null, "trname", "fname", "tfile", true); + trfea.BuildEventContext = buildEventContext; + es.Consume(trfea); - ProjectFinishedEventArgs pfea = new ProjectFinishedEventArgs("pf", null, "fname", true); - pfea.BuildEventContext = buildEventContext; - es.Consume(pfea); + ProjectFinishedEventArgs pfea = new ProjectFinishedEventArgs("pf", null, "fname", true); + pfea.BuildEventContext = buildEventContext; + es.Consume(pfea); - BuildFinishedEventArgs bfea = new BuildFinishedEventArgs("bf", null, true); - bfea.BuildEventContext = buildEventContext; - es.Consume(bfea); + BuildFinishedEventArgs bfea = new BuildFinishedEventArgs("bf", null, true); + bfea.BuildEventContext = buildEventContext; + es.Consume(bfea); - sc.ToString().ShouldBeEmpty(); - } + sc.ToString().ShouldBeEmpty(); } /// @@ -969,73 +905,58 @@ public void TestMinimalWithNormalMessage() [Fact] public void TestMinimalWithError() { - for (int i = 1; i <= 2; i++) - { - EventSourceSink es = new EventSourceSink(); - SimulatedConsole sc = new SimulatedConsole(); - ConsoleLogger L = new ConsoleLogger(LoggerVerbosity.Minimal, - sc.Write, sc.SetColor, sc.ResetColor); - L.Initialize(es, i); + EventSourceSink es = new EventSourceSink(); + SimulatedConsole sc = new SimulatedConsole(); + ConsoleLogger L = new ConsoleLogger(LoggerVerbosity.Minimal, + sc.Write, sc.SetColor, sc.ResetColor); + L.Initialize(es); - BuildEventContext buildEventContext = new BuildEventContext(1, 2, 3, 4); + BuildEventContext buildEventContext = new BuildEventContext(1, 2, 3, 4); - BuildStartedEventArgs bse = new BuildStartedEventArgs("bs", null); - bse.BuildEventContext = buildEventContext; - es.Consume(bse); + BuildStartedEventArgs bse = new BuildStartedEventArgs("bs", null); + bse.BuildEventContext = buildEventContext; + es.Consume(bse); - ProjectStartedEventArgs pse = new ProjectStartedEventArgs(-1, "ps", null, "fname", "", null, null, new BuildEventContext(1, 2, 3, 4)); - pse.BuildEventContext = buildEventContext; - es.Consume(pse); + ProjectStartedEventArgs pse = new ProjectStartedEventArgs(-1, "ps", null, "fname", "", null, null, new BuildEventContext(1, 2, 3, 4)); + pse.BuildEventContext = buildEventContext; + es.Consume(pse); - TargetStartedEventArgs trse = new TargetStartedEventArgs("ts", null, "trname", "pfile", "tfile"); - trse.BuildEventContext = buildEventContext; - es.Consume(trse); + TargetStartedEventArgs trse = new TargetStartedEventArgs("ts", null, "trname", "pfile", "tfile"); + trse.BuildEventContext = buildEventContext; + es.Consume(trse); - TaskStartedEventArgs tase = new TaskStartedEventArgs("tks", null, "tname", "tfname", "tsname"); - tase.BuildEventContext = buildEventContext; - es.Consume(tase); + TaskStartedEventArgs tase = new TaskStartedEventArgs("tks", null, "tname", "tfname", "tsname"); + tase.BuildEventContext = buildEventContext; + es.Consume(tase); - BuildErrorEventArgs beea = new BuildErrorEventArgs("VBC", - "31415", "file.vb", 42, 0, 0, 0, - "Some long message", "help", "sender"); + BuildErrorEventArgs beea = new BuildErrorEventArgs("VBC", + "31415", "file.vb", 42, 0, 0, 0, + "Some long message", "help", "sender"); - beea.BuildEventContext = buildEventContext; - es.Consume(beea); + beea.BuildEventContext = buildEventContext; + es.Consume(beea); - TaskFinishedEventArgs tafea = new TaskFinishedEventArgs("tkf", null, "fname", "tsname", "tfname", true); - tafea.BuildEventContext = buildEventContext; - es.Consume(tafea); + TaskFinishedEventArgs tafea = new TaskFinishedEventArgs("tkf", null, "fname", "tsname", "tfname", true); + tafea.BuildEventContext = buildEventContext; + es.Consume(tafea); - TargetFinishedEventArgs trfea = new TargetFinishedEventArgs("tf", null, "trname", "fname", "tfile", true); - trfea.BuildEventContext = buildEventContext; - es.Consume(trfea); + TargetFinishedEventArgs trfea = new TargetFinishedEventArgs("tf", null, "trname", "fname", "tfile", true); + trfea.BuildEventContext = buildEventContext; + es.Consume(trfea); - ProjectFinishedEventArgs pfea = new ProjectFinishedEventArgs("pf", null, "fname", true); - pfea.BuildEventContext = buildEventContext; - es.Consume(pfea); + ProjectFinishedEventArgs pfea = new ProjectFinishedEventArgs("pf", null, "fname", true); + pfea.BuildEventContext = buildEventContext; + es.Consume(pfea); - BuildFinishedEventArgs bfea = new BuildFinishedEventArgs("bf", null, true); - bfea.BuildEventContext = buildEventContext; - es.Consume(bfea); + BuildFinishedEventArgs bfea = new BuildFinishedEventArgs("bf", null, true); + bfea.BuildEventContext = buildEventContext; + es.Consume(bfea); - _output.WriteLine("=="); - _output.WriteLine(sc.ToString()); - _output.WriteLine("=="); + _output.WriteLine("=="); + _output.WriteLine(sc.ToString()); + _output.WriteLine("=="); - if (i == 1) - { - sc.ToString().ShouldBe( - "" + BaseConsoleLogger.projectSeparatorLine + Environment.NewLine + - ResourceUtilities.FormatResourceStringStripCodeAndKeyword("ProjectStartedPrefixForTopLevelProjectWithDefaultTargets", "fname") + Environment.NewLine + Environment.NewLine + - "file.vb(42): VBC error 31415: Some long message" + Environment.NewLine + - "pf" + Environment.NewLine + - ""); - } - else - { - sc.ToString().ShouldBe("file.vb(42): VBC error 31415: Some long message" + Environment.NewLine + ""); - } - } + sc.ToString().ShouldBe("file.vb(42): VBC error 31415: Some long message" + Environment.NewLine + ""); } /// @@ -1044,74 +965,59 @@ public void TestMinimalWithError() [Fact] public void TestMinimalWithWarning() { - for (int i = 1; i <= 2; i++) - { - EventSourceSink es = new EventSourceSink(); - SimulatedConsole sc = new SimulatedConsole(); - ConsoleLogger L = new ConsoleLogger(LoggerVerbosity.Quiet, - sc.Write, sc.SetColor, sc.ResetColor); - L.Initialize(es, i); + EventSourceSink es = new EventSourceSink(); + SimulatedConsole sc = new SimulatedConsole(); + ConsoleLogger L = new ConsoleLogger(LoggerVerbosity.Quiet, + sc.Write, sc.SetColor, sc.ResetColor); + L.Initialize(es); - BuildEventContext buildEventContext = new BuildEventContext(1, 2, 3, 4); + BuildEventContext buildEventContext = new BuildEventContext(1, 2, 3, 4); - BuildStartedEventArgs bse = new BuildStartedEventArgs("bs", null); - bse.BuildEventContext = buildEventContext; - es.Consume(bse); + BuildStartedEventArgs bse = new BuildStartedEventArgs("bs", null); + bse.BuildEventContext = buildEventContext; + es.Consume(bse); - ProjectStartedEventArgs pse = new ProjectStartedEventArgs(-1, "ps", null, "fname", "", null, null, new BuildEventContext(1, 2, 3, 4)); - pse.BuildEventContext = buildEventContext; - es.Consume(pse); + ProjectStartedEventArgs pse = new ProjectStartedEventArgs(-1, "ps", null, "fname", "", null, null, new BuildEventContext(1, 2, 3, 4)); + pse.BuildEventContext = buildEventContext; + es.Consume(pse); - TargetStartedEventArgs trse = new TargetStartedEventArgs("ts", null, "trname", "pfile", "tfile"); - trse.BuildEventContext = buildEventContext; - es.Consume(trse); + TargetStartedEventArgs trse = new TargetStartedEventArgs("ts", null, "trname", "pfile", "tfile"); + trse.BuildEventContext = buildEventContext; + es.Consume(trse); - TaskStartedEventArgs tase = new TaskStartedEventArgs("tks", null, "tname", "tfname", "tsname"); - tase.BuildEventContext = buildEventContext; - es.Consume(tase); + TaskStartedEventArgs tase = new TaskStartedEventArgs("tks", null, "tname", "tfname", "tsname"); + tase.BuildEventContext = buildEventContext; + es.Consume(tase); - BuildWarningEventArgs beea = new BuildWarningEventArgs("VBC", - "31415", "file.vb", 42, 0, 0, 0, - "Some long message", "help", "sender"); + BuildWarningEventArgs beea = new BuildWarningEventArgs("VBC", + "31415", "file.vb", 42, 0, 0, 0, + "Some long message", "help", "sender"); - beea.BuildEventContext = buildEventContext; - es.Consume(beea); + beea.BuildEventContext = buildEventContext; + es.Consume(beea); - TaskFinishedEventArgs tafea = new TaskFinishedEventArgs("tkf", null, "fname", "tsname", "tfname", true); - tafea.BuildEventContext = buildEventContext; - es.Consume(tafea); + TaskFinishedEventArgs tafea = new TaskFinishedEventArgs("tkf", null, "fname", "tsname", "tfname", true); + tafea.BuildEventContext = buildEventContext; + es.Consume(tafea); - TargetFinishedEventArgs trfea = new TargetFinishedEventArgs("tf", null, "trname", "fname", "tfile", true); - trfea.BuildEventContext = buildEventContext; - es.Consume(trfea); + TargetFinishedEventArgs trfea = new TargetFinishedEventArgs("tf", null, "trname", "fname", "tfile", true); + trfea.BuildEventContext = buildEventContext; + es.Consume(trfea); - ProjectFinishedEventArgs pfea = new ProjectFinishedEventArgs("pf", null, "fname", true); - pfea.BuildEventContext = buildEventContext; - es.Consume(pfea); + ProjectFinishedEventArgs pfea = new ProjectFinishedEventArgs("pf", null, "fname", true); + pfea.BuildEventContext = buildEventContext; + es.Consume(pfea); - BuildFinishedEventArgs bfea = new BuildFinishedEventArgs("bf", null, true); - bfea.BuildEventContext = buildEventContext; - es.Consume(bfea); + BuildFinishedEventArgs bfea = new BuildFinishedEventArgs("bf", null, true); + bfea.BuildEventContext = buildEventContext; + es.Consume(bfea); - _output.WriteLine("=="); - _output.WriteLine(sc.ToString()); - _output.WriteLine("=="); + _output.WriteLine("=="); + _output.WriteLine(sc.ToString()); + _output.WriteLine("=="); - if (i == 1) - { - sc.ToString().ShouldBe( - "" + BaseConsoleLogger.projectSeparatorLine + Environment.NewLine + - ResourceUtilities.FormatResourceStringStripCodeAndKeyword("ProjectStartedPrefixForTopLevelProjectWithDefaultTargets", "fname") + Environment.NewLine + Environment.NewLine + - "file.vb(42): VBC warning 31415: Some long message" + Environment.NewLine + - "pf" + Environment.NewLine + - ""); - } - else - { - sc.ToString().ShouldBe("file.vb(42): VBC warning 31415: Some long message" + Environment.NewLine + ""); - } - } + sc.ToString().ShouldBe("file.vb(42): VBC warning 31415: Some long message" + Environment.NewLine + ""); } /// @@ -1119,205 +1025,73 @@ public void TestMinimalWithWarning() /// [Fact] public void TestDirectEventHandlers() - { - for (int i = 1; i <= 2; i++) - { - EventSourceSink es = new EventSourceSink(); - SimulatedConsole sc = new SimulatedConsole(); - ConsoleLogger L = new ConsoleLogger(LoggerVerbosity.Quiet, - sc.Write, sc.SetColor, sc.ResetColor); - L.Initialize(es, i); - - BuildEventContext buildEventContext = new BuildEventContext(1, 2, 3, 4); - - BuildStartedEventArgs bse = new BuildStartedEventArgs("bs", null); - bse.BuildEventContext = buildEventContext; - L.BuildStartedHandler(null, bse); - - ProjectStartedEventArgs pse = new ProjectStartedEventArgs(-1, "ps", null, "fname", "", null, null, new BuildEventContext(1, 2, 3, 4)); - pse.BuildEventContext = buildEventContext; - L.ProjectStartedHandler(null, pse); - - TargetStartedEventArgs trse = new TargetStartedEventArgs("ts", null, "trname", "pfile", "tfile"); - trse.BuildEventContext = buildEventContext; - L.TargetStartedHandler(null, trse); - - TaskStartedEventArgs tase = new TaskStartedEventArgs("tks", null, "tname", "tfname", "tsname"); - tase.BuildEventContext = buildEventContext; - L.TaskStartedHandler(null, tase); - - BuildWarningEventArgs beea = new BuildWarningEventArgs("VBC", - "31415", "file.vb", 42, 0, 0, 0, - "Some long message", "help", "sender"); - - - beea.BuildEventContext = buildEventContext; - L.WarningHandler(null, beea); - - TaskFinishedEventArgs tafea = new TaskFinishedEventArgs("tkf", null, "fname", "tsname", "tfname", true); - tafea.BuildEventContext = buildEventContext; - L.TaskFinishedHandler(null, tafea); - - TargetFinishedEventArgs trfea = new TargetFinishedEventArgs("tf", null, "trname", "fname", "tfile", true); - trfea.BuildEventContext = buildEventContext; - L.TargetFinishedHandler(null, trfea); - - ProjectFinishedEventArgs pfea = new ProjectFinishedEventArgs("pf", null, "fname", true); - pfea.BuildEventContext = buildEventContext; - L.ProjectFinishedHandler(null, pfea); - - BuildFinishedEventArgs bfea = new BuildFinishedEventArgs("bf", null, true); - bfea.BuildEventContext = buildEventContext; - L.BuildFinishedHandler(null, bfea); - - _output.WriteLine("=="); - _output.WriteLine(sc.ToString()); - _output.WriteLine("=="); - - if (i == 1) - { - sc.ToString().ShouldBe( - "" + BaseConsoleLogger.projectSeparatorLine + Environment.NewLine + - ResourceUtilities.FormatResourceStringStripCodeAndKeyword("ProjectStartedPrefixForTopLevelProjectWithDefaultTargets", "fname") + Environment.NewLine + Environment.NewLine + - "file.vb(42): VBC warning 31415: Some long message" + Environment.NewLine + - "pf" + Environment.NewLine + - ""); - } - else - { - sc.ToString().ShouldBe("file.vb(42): VBC warning 31415: Some long message" + Environment.NewLine + ""); - } - } - } - - [Fact] - public void NestedProjectMinimal() { EventSourceSink es = new EventSourceSink(); SimulatedConsole sc = new SimulatedConsole(); - ConsoleLogger L = new ConsoleLogger(LoggerVerbosity.Minimal, - sc.Write, sc.SetColor, sc.ResetColor); - L.Initialize(es, 1); - - es.Consume(new BuildStartedEventArgs("bs", null)); - - // Clear time dependent build started message - sc.Clear(); - - es.Consume(new ProjectStartedEventArgs("ps1", null, "fname1", "", null, null)); - - es.Consume(new TargetStartedEventArgs("ts", null, - "trname", "fname", "tfile")); - - es.Consume(new ProjectStartedEventArgs("ps2", null, "fname2", "", null, null)); - - sc.ToString().ShouldBeEmpty(); - - BuildErrorEventArgs beea = new BuildErrorEventArgs("VBC", - "31415", "file.vb", 42, 0, 0, 0, - "Some long message", "help", "sender"); - - es.Consume(beea); - - sc.ToString().ShouldBe( - "" + BaseConsoleLogger.projectSeparatorLine + Environment.NewLine + - ResourceUtilities.FormatResourceStringStripCodeAndKeyword("ProjectStartedPrefixForTopLevelProjectWithDefaultTargets", "fname1") + Environment.NewLine + - Environment.NewLine + "" + - "" + BaseConsoleLogger.projectSeparatorLine + Environment.NewLine + - ResourceUtilities.FormatResourceStringStripCodeAndKeyword("ProjectStartedPrefixForNestedProjectWithDefaultTargets", "fname1", "fname2") + Environment.NewLine + - Environment.NewLine + "" + - "" + "file.vb(42): VBC error 31415: Some long message" + - Environment.NewLine + ""); - } - - [Fact] - public void NestedProjectNormal() - { - EventSourceSink es = new EventSourceSink(); - SimulatedConsole sc = new SimulatedConsole(); - ConsoleLogger L = new ConsoleLogger(LoggerVerbosity.Normal, + ConsoleLogger L = new ConsoleLogger(LoggerVerbosity.Quiet, sc.Write, sc.SetColor, sc.ResetColor); L.Initialize(es); - es.Consume(new BuildStartedEventArgs("bs", null)); - - - // Clear time dependent build started message - sc.Clear(); - - es.Consume(new ProjectStartedEventArgs("ps1", null, "fname1", "", null, null)); - - sc.ToString().ShouldBe("" + BaseConsoleLogger.projectSeparatorLine + Environment.NewLine + - ResourceUtilities.FormatResourceStringStripCodeAndKeyword("ProjectStartedPrefixForTopLevelProjectWithDefaultTargets", "fname1") + Environment.NewLine + - Environment.NewLine + ""); - - sc.Clear(); - - es.Consume(new TargetStartedEventArgs("ts", null, - "tarname", "fname", "tfile")); - sc.ToString().ShouldBeEmpty(); - - sc.Clear(); - - es.Consume(new TaskStartedEventArgs("", "", "", "", "Exec")); - es.Consume(new ProjectStartedEventArgs("ps2", null, "fname2", "", null, null)); - - sc.ToString().ShouldBe( - "" + ResourceUtilities.FormatResourceStringStripCodeAndKeyword("TargetStartedPrefix", "tarname") + Environment.NewLine + "" - + "" + " " + BaseConsoleLogger.projectSeparatorLine - + Environment.NewLine + - " " + ResourceUtilities.FormatResourceStringStripCodeAndKeyword("ProjectStartedPrefixForNestedProjectWithDefaultTargets", "fname1", "fname2") + Environment.NewLine + - Environment.NewLine + ""); - - sc.Clear(); + BuildEventContext buildEventContext = new BuildEventContext(1, 2, 3, 4); - es.Consume(new ProjectFinishedEventArgs("pf2", null, "fname2", true)); - es.Consume(new TaskFinishedEventArgs("", "", "", "", "Exec", true)); + BuildStartedEventArgs bse = new BuildStartedEventArgs("bs", null); + bse.BuildEventContext = buildEventContext; + L.BuildStartedHandler(null, bse); - sc.ToString().ShouldBeEmpty(); + ProjectStartedEventArgs pse = new ProjectStartedEventArgs(-1, "ps", null, "fname", "", null, null, new BuildEventContext(1, 2, 3, 4)); + pse.BuildEventContext = buildEventContext; + L.ProjectStartedHandler(null, pse); - sc.Clear(); + TargetStartedEventArgs trse = new TargetStartedEventArgs("ts", null, "trname", "pfile", "tfile"); + trse.BuildEventContext = buildEventContext; + L.TargetStartedHandler(null, trse); - es.Consume(new TargetFinishedEventArgs("tf", null, "tarname", "fname", "tfile", true)); + TaskStartedEventArgs tase = new TaskStartedEventArgs("tks", null, "tname", "tfname", "tsname"); + tase.BuildEventContext = buildEventContext; + L.TaskStartedHandler(null, tase); - sc.ToString().ShouldBeEmpty(); + BuildWarningEventArgs beea = new BuildWarningEventArgs("VBC", + "31415", "file.vb", 42, 0, 0, 0, + "Some long message", "help", "sender"); - sc.Clear(); - es.Consume(new ProjectFinishedEventArgs("pf1", null, "fname1", true)); + beea.BuildEventContext = buildEventContext; + L.WarningHandler(null, beea); - sc.ToString().ShouldBeEmpty(); + TaskFinishedEventArgs tafea = new TaskFinishedEventArgs("tkf", null, "fname", "tsname", "tfname", true); + tafea.BuildEventContext = buildEventContext; + L.TaskFinishedHandler(null, tafea); - sc.Clear(); + TargetFinishedEventArgs trfea = new TargetFinishedEventArgs("tf", null, "trname", "fname", "tfile", true); + trfea.BuildEventContext = buildEventContext; + L.TargetFinishedHandler(null, trfea); - es.Consume(new BuildFinishedEventArgs("bf", null, true)); + ProjectFinishedEventArgs pfea = new ProjectFinishedEventArgs("pf", null, "fname", true); + pfea.BuildEventContext = buildEventContext; + L.ProjectFinishedHandler(null, pfea); - sc.ToString().ShouldStartWith("" + Environment.NewLine + "bf" + - Environment.NewLine + "" + - " " + ResourceUtilities.FormatResourceStringStripCodeAndKeyword("WarningCount", 0) + - Environment.NewLine + "" + - " " + ResourceUtilities.FormatResourceStringStripCodeAndKeyword("ErrorCount", 0) + - Environment.NewLine + "" + - Environment.NewLine); + BuildFinishedEventArgs bfea = new BuildFinishedEventArgs("bf", null, true); + bfea.BuildEventContext = buildEventContext; + L.BuildFinishedHandler(null, bfea); - // Would like to add... - // + ResourceUtilities.FormatResourceString("TimeElapsed", String.Empty); - // ...but this assumes that the time goes on the far right in every locale. + _output.WriteLine("=="); + _output.WriteLine(sc.ToString()); + _output.WriteLine("=="); - sc.Clear(); + sc.ToString().ShouldBe("file.vb(42): VBC warning 31415: Some long message" + Environment.NewLine + ""); } + [Fact] public void CustomDisplayedAtDetailed() { EventSourceSink es = new EventSourceSink(); SimulatedConsole sc = new SimulatedConsole(); - ConsoleLogger L = new ConsoleLogger(LoggerVerbosity.Detailed, - sc.Write, null, null); + ConsoleLogger L = new ConsoleLogger(LoggerVerbosity.Detailed, sc.Write, null, null); L.Initialize(es); - MyCustomBuildEventArgs c = - new MyCustomBuildEventArgs("msg"); + MyCustomBuildEventArgs c = new MyCustomBuildEventArgs("msg"); + c.BuildEventContext = new BuildEventContext(1, 1, 1, 1); es.Consume(c); @@ -1346,12 +1120,11 @@ public void CustomNotDisplayedAtNormal() { EventSourceSink es = new EventSourceSink(); SimulatedConsole sc = new SimulatedConsole(); - ConsoleLogger L = new ConsoleLogger(LoggerVerbosity.Normal, - sc.Write, null, null); + ConsoleLogger L = new ConsoleLogger(LoggerVerbosity.Normal, sc.Write, null, null); L.Initialize(es); - MyCustomBuildEventArgs c = - new MyCustomBuildEventArgs("msg"); + MyCustomBuildEventArgs c = new MyCustomBuildEventArgs("msg"); + c.BuildEventContext = new BuildEventContext(1, 1, 1, 1); es.Consume(c); @@ -1761,16 +1534,14 @@ public void ResetConsoleLoggerStateTestBasic() es.Consume(new BuildStartedEventArgs("bs", null)); // Introduce a warning - BuildWarningEventArgs bwea = new BuildWarningEventArgs("VBC", - "31415", "file.vb", 42, 0, 0, 0, - "Some long message", "help", "sender"); + BuildWarningEventArgs bwea = new BuildWarningEventArgs("VBC", "31415", "file.vb", 42, 0, 0, 0, "Some long message", "help", "sender"); + bwea.BuildEventContext = new BuildEventContext(1, 1, 1, 1); es.Consume(bwea); // Introduce an error - BuildErrorEventArgs beea = new BuildErrorEventArgs("VBC", - "31415", "file.vb", 42, 0, 0, 0, - "Some long message", "help", "sender"); + BuildErrorEventArgs beea = new BuildErrorEventArgs("VBC", "31415", "file.vb", 42, 0, 0, 0, "Some long message", "help", "sender"); + beea.BuildEventContext = new BuildEventContext(1, 1, 1, 1); es.Consume(beea); @@ -1842,8 +1613,7 @@ public void ResetConsoleLoggerState_Initialize() string warningString = ResourceUtilities.FormatResourceStringStripCodeAndKeyword("WarningCount", 1); // Create a ConsoleLogger with Normal verbosity - ConsoleLogger L = new ConsoleLogger(LoggerVerbosity.Normal, - sc.Write, sc.SetColor, sc.ResetColor); + ConsoleLogger L = new ConsoleLogger(LoggerVerbosity.Normal, sc.Write, sc.SetColor, sc.ResetColor); // Initialize ConsoleLogger L.Initialize(es); @@ -1851,16 +1621,14 @@ public void ResetConsoleLoggerState_Initialize() es.Consume(new BuildStartedEventArgs("bs", null)); // Introduce a warning - BuildWarningEventArgs bwea = new BuildWarningEventArgs("VBC", - "31415", "file.vb", 42, 0, 0, 0, - "Some long message", "help", "sender"); + BuildWarningEventArgs bwea = new BuildWarningEventArgs("VBC", "31415", "file.vb", 42, 0, 0, 0, "Some long message", "help", "sender"); + bwea.BuildEventContext = new BuildEventContext(1, 1, 1, 1); es.Consume(bwea); // Introduce an error - BuildErrorEventArgs beea = new BuildErrorEventArgs("VBC", - "31415", "file.vb", 42, 0, 0, 0, - "Some long message", "help", "sender"); + BuildErrorEventArgs beea = new BuildErrorEventArgs("VBC", "31415", "file.vb", 42, 0, 0, 0, "Some long message", "help", "sender"); + beea.BuildEventContext = new BuildEventContext(1, 1, 1, 1); es.Consume(beea); @@ -1889,8 +1657,7 @@ public void ResetConsoleLoggerState_Initialize() es.Consume(new BuildStartedEventArgs("bs", null)); // BuildFinished - es.Consume(new BuildFinishedEventArgs("bf", - null, true)); + es.Consume(new BuildFinishedEventArgs("bf", null, true)); // Log so far actualLog = sc.ToString(); @@ -1919,127 +1686,124 @@ public void ResetConsoleLoggerState_Initialize() [Fact] public void ResetConsoleLoggerState_PerformanceCounters() { - for (int i = 1; i <= 2; i++) - { - EventSourceSink es = new EventSourceSink(); - // Create a simulated console - SimulatedConsole sc = new SimulatedConsole(); - // Create a ConsoleLogger with Normal verbosity - ConsoleLogger L = new ConsoleLogger(LoggerVerbosity.Normal, sc.Write, sc.SetColor, sc.ResetColor); - // Initialize ConsoleLogger - L.Parameters = "Performancesummary"; - L.Initialize(es, i); - // prjPerfString = Project Performance Summary: - string prjPerfString = ResourceUtilities.FormatResourceStringStripCodeAndKeyword("ProjectPerformanceSummary", null); - // targetPerfString = Target Performance Summary: - string targetPerfString = ResourceUtilities.FormatResourceStringStripCodeAndKeyword("TargetPerformanceSummary", null); - // taskPerfString = Task Performance Summary: - string taskPerfString = ResourceUtilities.FormatResourceStringStripCodeAndKeyword("TaskPerformanceSummary", null); - - // BuildStarted Event - es.Consume(new BuildStartedEventArgs("bs", null)); - // Project Started Event - ProjectStartedEventArgs project1Started = new ProjectStartedEventArgs(1, null, null, "p", "t", null, null, new BuildEventContext(BuildEventContext.InvalidNodeId, BuildEventContext.InvalidTargetId, BuildEventContext.InvalidProjectContextId, BuildEventContext.InvalidTaskId)); - project1Started.BuildEventContext = new BuildEventContext(1, 1, 1, 1); - es.Consume(project1Started); - TargetStartedEventArgs targetStarted1 = new TargetStartedEventArgs(null, null, "t", null, null); - targetStarted1.BuildEventContext = project1Started.BuildEventContext; - // TargetStarted Event - es.Consume(targetStarted1); + EventSourceSink es = new EventSourceSink(); + // Create a simulated console + SimulatedConsole sc = new SimulatedConsole(); + // Create a ConsoleLogger with Normal verbosity + ConsoleLogger L = new ConsoleLogger(LoggerVerbosity.Normal, sc.Write, sc.SetColor, sc.ResetColor); + // Initialize ConsoleLogger + L.Parameters = "Performancesummary"; + L.Initialize(es); + // prjPerfString = Project Performance Summary: + string prjPerfString = ResourceUtilities.FormatResourceStringStripCodeAndKeyword("ProjectPerformanceSummary", null); + // targetPerfString = Target Performance Summary: + string targetPerfString = ResourceUtilities.FormatResourceStringStripCodeAndKeyword("TargetPerformanceSummary", null); + // taskPerfString = Task Performance Summary: + string taskPerfString = ResourceUtilities.FormatResourceStringStripCodeAndKeyword("TaskPerformanceSummary", null); - TaskStartedEventArgs taskStarted1 = new TaskStartedEventArgs(null, null, null, null, "task"); - taskStarted1.BuildEventContext = project1Started.BuildEventContext; - // TaskStarted Event - es.Consume(taskStarted1); + // BuildStarted Event + es.Consume(new BuildStartedEventArgs("bs", null)); + // Project Started Event + ProjectStartedEventArgs project1Started = new ProjectStartedEventArgs(1, null, null, "p", "t", null, null, new BuildEventContext(BuildEventContext.InvalidNodeId, BuildEventContext.InvalidTargetId, BuildEventContext.InvalidProjectContextId, BuildEventContext.InvalidTaskId)); + project1Started.BuildEventContext = new BuildEventContext(1, 1, 1, 1); + es.Consume(project1Started); + TargetStartedEventArgs targetStarted1 = new TargetStartedEventArgs(null, null, "t", null, null); + targetStarted1.BuildEventContext = project1Started.BuildEventContext; + // TargetStarted Event + es.Consume(targetStarted1); - BuildMessageEventArgs messsage1 = new BuildMessageEventArgs(null, null, null, MessageImportance.High); - messsage1.BuildEventContext = project1Started.BuildEventContext; - // Message Event - es.Consume(messsage1); - TaskFinishedEventArgs taskFinished1 = new TaskFinishedEventArgs(null, null, null, null, "task", true); - taskFinished1.BuildEventContext = project1Started.BuildEventContext; - // TaskFinished Event - es.Consume(taskFinished1); - - TargetFinishedEventArgs targetFinished1 = new TargetFinishedEventArgs(null, null, "t", null, null, true); - targetFinished1.BuildEventContext = project1Started.BuildEventContext; - // TargetFinished Event - es.Consume(targetFinished1); - - ProjectStartedEventArgs project2Started = new ProjectStartedEventArgs(2, null, null, "p2", "t2", null, null, project1Started.BuildEventContext); - // Project Started Event - project2Started.BuildEventContext = new BuildEventContext(2, 2, 2, 2); - es.Consume(project2Started); - TargetStartedEventArgs targetStarted2 = new TargetStartedEventArgs(null, null, "t2", null, null); - targetStarted2.BuildEventContext = project2Started.BuildEventContext; - // TargetStarted Event - es.Consume(targetStarted2); - - TaskStartedEventArgs taskStarted2 = new TaskStartedEventArgs(null, null, null, null, "task2"); - taskStarted2.BuildEventContext = project2Started.BuildEventContext; - // TaskStarted Event - es.Consume(taskStarted2); - - BuildMessageEventArgs messsage2 = new BuildMessageEventArgs(null, null, null, MessageImportance.High); - messsage2.BuildEventContext = project2Started.BuildEventContext; - // Message Event - es.Consume(messsage2); - TaskFinishedEventArgs taskFinished2 = new TaskFinishedEventArgs(null, null, null, null, "task2", true); - taskFinished2.BuildEventContext = project2Started.BuildEventContext; - // TaskFinished Event - es.Consume(taskFinished2); - - TargetFinishedEventArgs targetFinished2 = new TargetFinishedEventArgs(null, null, "t2", null, null, true); - targetFinished2.BuildEventContext = project2Started.BuildEventContext; - // TargetFinished Event - es.Consume(targetFinished2); - - ProjectFinishedEventArgs finished2 = new ProjectFinishedEventArgs(null, null, "p2", true); - finished2.BuildEventContext = project2Started.BuildEventContext; - // ProjectFinished Event - es.Consume(finished2); // BuildFinished Event - - ProjectFinishedEventArgs finished1 = new ProjectFinishedEventArgs(null, null, "p", true); - finished1.BuildEventContext = project1Started.BuildEventContext; - // ProjectFinished Event - es.Consume(finished1); // BuildFinished Event - es.Consume(new BuildFinishedEventArgs("bf", - null, true)); - // Log so far - string actualLog = sc.ToString(); + TaskStartedEventArgs taskStarted1 = new TaskStartedEventArgs(null, null, null, null, "task"); + taskStarted1.BuildEventContext = project1Started.BuildEventContext; + // TaskStarted Event + es.Consume(taskStarted1); + + BuildMessageEventArgs messsage1 = new BuildMessageEventArgs(null, null, null, MessageImportance.High); + messsage1.BuildEventContext = project1Started.BuildEventContext; + // Message Event + es.Consume(messsage1); + TaskFinishedEventArgs taskFinished1 = new TaskFinishedEventArgs(null, null, null, null, "task", true); + taskFinished1.BuildEventContext = project1Started.BuildEventContext; + // TaskFinished Event + es.Consume(taskFinished1); + + TargetFinishedEventArgs targetFinished1 = new TargetFinishedEventArgs(null, null, "t", null, null, true); + targetFinished1.BuildEventContext = project1Started.BuildEventContext; + // TargetFinished Event + es.Consume(targetFinished1); + + ProjectStartedEventArgs project2Started = new ProjectStartedEventArgs(2, null, null, "p2", "t2", null, null, project1Started.BuildEventContext); + // Project Started Event + project2Started.BuildEventContext = new BuildEventContext(2, 2, 2, 2); + es.Consume(project2Started); + TargetStartedEventArgs targetStarted2 = new TargetStartedEventArgs(null, null, "t2", null, null); + targetStarted2.BuildEventContext = project2Started.BuildEventContext; + // TargetStarted Event + es.Consume(targetStarted2); + + TaskStartedEventArgs taskStarted2 = new TaskStartedEventArgs(null, null, null, null, "task2"); + taskStarted2.BuildEventContext = project2Started.BuildEventContext; + // TaskStarted Event + es.Consume(taskStarted2); + + BuildMessageEventArgs messsage2 = new BuildMessageEventArgs(null, null, null, MessageImportance.High); + messsage2.BuildEventContext = project2Started.BuildEventContext; + // Message Event + es.Consume(messsage2); + TaskFinishedEventArgs taskFinished2 = new TaskFinishedEventArgs(null, null, null, null, "task2", true); + taskFinished2.BuildEventContext = project2Started.BuildEventContext; + // TaskFinished Event + es.Consume(taskFinished2); + + TargetFinishedEventArgs targetFinished2 = new TargetFinishedEventArgs(null, null, "t2", null, null, true); + targetFinished2.BuildEventContext = project2Started.BuildEventContext; + // TargetFinished Event + es.Consume(targetFinished2); + + ProjectFinishedEventArgs finished2 = new ProjectFinishedEventArgs(null, null, "p2", true); + finished2.BuildEventContext = project2Started.BuildEventContext; + // ProjectFinished Event + es.Consume(finished2); // BuildFinished Event + + ProjectFinishedEventArgs finished1 = new ProjectFinishedEventArgs(null, null, "p", true); + finished1.BuildEventContext = project1Started.BuildEventContext; + // ProjectFinished Event + es.Consume(finished1); // BuildFinished Event + es.Consume(new BuildFinishedEventArgs("bf", + null, true)); + // Log so far + string actualLog = sc.ToString(); - _output.WriteLine("=="); - _output.WriteLine(sc.ToString()); - _output.WriteLine("=="); + _output.WriteLine("=="); + _output.WriteLine(sc.ToString()); + _output.WriteLine("=="); - // Verify that the log has perf summary - // Project perf summary - actualLog.ShouldContain(prjPerfString); - // Target perf summary - actualLog.ShouldContain(targetPerfString); - // Task Perf summary - actualLog.ShouldContain(taskPerfString); + // Verify that the log has perf summary + // Project perf summary + actualLog.ShouldContain(prjPerfString); + // Target perf summary + actualLog.ShouldContain(targetPerfString); + // Task Perf summary + actualLog.ShouldContain(taskPerfString); - // Clear the log obtained so far - sc.Clear(); + // Clear the log obtained so far + sc.Clear(); - // BuildStarted event - es.Consume(new BuildStartedEventArgs("bs", null)); - // BuildFinished - es.Consume(new BuildFinishedEventArgs("bf", - null, true)); - // Log so far - actualLog = sc.ToString(); - - _output.WriteLine("=="); - _output.WriteLine(sc.ToString()); - _output.WriteLine("=="); - - // Verify that the log doesn't have perf summary - actualLog.ShouldNotContain(prjPerfString); - actualLog.ShouldNotContain(targetPerfString); - actualLog.ShouldNotContain(taskPerfString); - } + // BuildStarted event + es.Consume(new BuildStartedEventArgs("bs", null)); + // BuildFinished + es.Consume(new BuildFinishedEventArgs("bf", + null, true)); + // Log so far + actualLog = sc.ToString(); + + _output.WriteLine("=="); + _output.WriteLine(sc.ToString()); + _output.WriteLine("=="); + + // Verify that the log doesn't have perf summary + actualLog.ShouldNotContain(prjPerfString); + actualLog.ShouldNotContain(targetPerfString); + actualLog.ShouldNotContain(taskPerfString); } @@ -2176,88 +1940,6 @@ public void TestPrintTargetNamePerMessage() actualLog.ShouldContain("t:"); } - /// - /// Verify that in the MP case and the older serial logger that there is no extra newline after the project done event. - /// We cannot verify there is a newline after the project done event for the MP single proc log because - /// nunit is showing up as an unknown output type, this causes us to not print the newline because we think it may be to a - /// text file. - /// - [Fact] - public void TestNewLineAfterProjectFinished() - { - bool runningWithCharDevice = NativeMethodsShared.IsWindows ? IsRunningWithCharacterFileType() : false; - for (int i = 0; i < 3; i++) - { - _output.WriteLine("Iteration of I is {" + i + "}"); - - - EventSourceSink es = new EventSourceSink(); - // Create a simulated console - SimulatedConsole sc = new SimulatedConsole(); - ConsoleLogger L = new ConsoleLogger(LoggerVerbosity.Normal, sc.Write, sc.SetColor, sc.ResetColor); - - if (i < 2) - { - // On the second pass through use the MP single proc logger - if (i == 1) - { - L.Parameters = "EnableMPLogging"; - } - // Use the old single proc logger - L.Initialize(es, 1); - } - else - { - // Use the parallel logger - L.Initialize(es, 2); - } - - es.Consume(new BuildStartedEventArgs("bs", null)); - BuildEventContext context = new BuildEventContext(1, 1, 1, 1); - - ProjectStartedEventArgs project = new ProjectStartedEventArgs(1, "Hello,", "HI", "None", "Build", null, null, context); - project.BuildEventContext = context; - es.Consume(project); - - TargetStartedEventArgs targetStarted1 = new TargetStartedEventArgs(null, null, "t", null, null); - targetStarted1.BuildEventContext = context; - es.Consume(targetStarted1); - - BuildMessageEventArgs messsage1 = new BuildMessageEventArgs("Message", null, null, MessageImportance.High); - messsage1.BuildEventContext = context; - es.Consume(messsage1); - - ProjectFinishedEventArgs projectFinished = new ProjectFinishedEventArgs("Finished,", "HI", "projectFile", true); - projectFinished.BuildEventContext = context; - es.Consume(projectFinished); - - string actualLog = sc.ToString(); - - switch (i) - { - case 0: - // There is no project finished event printed in normal verbosity - actualLog.ShouldNotContain(projectFinished.Message); - break; - // We are in single proc but logging with multiproc logging add an extra new line to make the log more readable. - case 1: - actualLog.ShouldContain(ResourceUtilities.FormatResourceStringStripCodeAndKeyword("ProjectFinishedPrefixWithTargetNamesMultiProc", "None", "Build") + Environment.NewLine); - if (runningWithCharDevice) - { - actualLog.ShouldContain(ResourceUtilities.FormatResourceStringStripCodeAndKeyword("ProjectFinishedPrefixWithTargetNamesMultiProc", "None", "Build") + Environment.NewLine + Environment.NewLine); - } - else - { - actualLog.ShouldNotContain(ResourceUtilities.FormatResourceStringStripCodeAndKeyword("ProjectFinishedPrefixWithTargetNamesMultiProc", "None", "Build") + Environment.NewLine + Environment.NewLine); - } - break; - case 2: - actualLog.ShouldNotContain(ResourceUtilities.FormatResourceStringStripCodeAndKeyword("ProjectFinishedPrefixWithTargetNamesMultiProc", "None", "Build") + Environment.NewLine + Environment.NewLine); - break; - } - } - } - /// /// Check to see what kind of device we are outputting the log to, is it a character device, a file, or something else /// this can be used by loggers to modify their outputs based on the device they are writing to diff --git a/src/Build.UnitTests/FileLogger_Tests.cs b/src/Build.UnitTests/FileLogger_Tests.cs index 92fe3050728..28161a9a783 100644 --- a/src/Build.UnitTests/FileLogger_Tests.cs +++ b/src/Build.UnitTests/FileLogger_Tests.cs @@ -58,11 +58,8 @@ public void BasicNoExistingFile() try { log = FileUtilities.GetTemporaryFileName(); - SetUpFileLoggerAndLogMessage("logfile=" + log, new BuildMessageEventArgs("message here", null, null, MessageImportance.High)); + SetUpFileLoggerAndLogMessage("logfile=" + log, new BuildMessageEventArgs("message here", null, null, MessageImportance.High) { BuildEventContext = new BuildEventContext(1, 1, 1, 1) }); VerifyFileContent(log, "message here"); - - byte[] content = ReadRawBytes(log); - Assert.Equal((byte)109, content[0]); // 'm' } finally { @@ -74,7 +71,7 @@ public void BasicNoExistingFile() } /// - /// Invalid file should error nicely + /// Invalid file should error nicely. /// [Fact] [Trait("Category", "netcore-osx-failing")] @@ -87,7 +84,7 @@ public void InvalidFile() try { - SetUpFileLoggerAndLogMessage("logfile=||invalid||", new BuildMessageEventArgs("message here", null, null, MessageImportance.High)); + SetUpFileLoggerAndLogMessage("logfile=||invalid||", new BuildMessageEventArgs("message here", null, null, MessageImportance.High) { BuildEventContext = new BuildEventContext(1, 1, 1, 1) }); } finally { @@ -114,7 +111,7 @@ public void SpecificVerbosity() fl.Parameters = "verbosity=diagnostic;logfile=" + log; // diagnostic specific setting fl.Verbosity = LoggerVerbosity.Quiet; // quiet global setting fl.Initialize(es); - fl.MessageHandler(null, new BuildMessageEventArgs("message here", null, null, MessageImportance.High)); + fl.MessageHandler(null, new BuildMessageEventArgs("message here", null, null, MessageImportance.High) { BuildEventContext = new BuildEventContext(1, 1, 1, 1) }); fl.Shutdown(); // expect message to appear because diagnostic not quiet verbosity was used @@ -216,7 +213,7 @@ public void ValidEncoding() try { log = FileUtilities.GetTemporaryFileName(); - SetUpFileLoggerAndLogMessage("encoding=utf-16;logfile=" + log, new BuildMessageEventArgs("message here", null, null, MessageImportance.High)); + SetUpFileLoggerAndLogMessage("encoding=utf-16;logfile=" + log, new BuildMessageEventArgs("message here", null, null, MessageImportance.High) { BuildEventContext = new BuildEventContext(1, 1, 1, 1) }); byte[] content = ReadRawBytes(log); // FF FE is the BOM for UTF16 @@ -243,7 +240,7 @@ public void ValidEncoding2() try { log = FileUtilities.GetTemporaryFileName(); - SetUpFileLoggerAndLogMessage("encoding=utf-8;logfile=" + log, new BuildMessageEventArgs("message here", null, null, MessageImportance.High)); + SetUpFileLoggerAndLogMessage("encoding=utf-8;logfile=" + log, new BuildMessageEventArgs("message here", null, null, MessageImportance.High) { BuildEventContext = new BuildEventContext(1, 1, 1, 1) }); byte[] content = ReadRawBytes(log); // EF BB BF is the BOM for UTF8 @@ -293,7 +290,7 @@ public void BasicExistingFileNoAppend() { log = FileUtilities.GetTemporaryFileName(); WriteContentToFile(log); - SetUpFileLoggerAndLogMessage("logfile=" + log, new BuildMessageEventArgs("message here", null, null, MessageImportance.High)); + SetUpFileLoggerAndLogMessage("logfile=" + log, new BuildMessageEventArgs("message here", null, null, MessageImportance.High) { BuildEventContext = new BuildEventContext(1, 1, 1, 1) }); VerifyFileContent(log, "message here"); } finally @@ -317,7 +314,7 @@ public void BasicExistingFileAppend() { log = FileUtilities.GetTemporaryFileName(); WriteContentToFile(log); - SetUpFileLoggerAndLogMessage("append;logfile=" + log, new BuildMessageEventArgs("message here", null, null, MessageImportance.High)); + SetUpFileLoggerAndLogMessage("append;logfile=" + log, new BuildMessageEventArgs("message here", null, null, MessageImportance.High) { BuildEventContext = new BuildEventContext(1, 1, 1, 1) }); VerifyFileContent(log, "existing content\nmessage here"); } finally @@ -342,7 +339,7 @@ public void BasicNoExistingDirectory() try { - SetUpFileLoggerAndLogMessage("logfile=" + log, new BuildMessageEventArgs("message here", null, null, MessageImportance.High)); + SetUpFileLoggerAndLogMessage("logfile=" + log, new BuildMessageEventArgs("message here", null, null, MessageImportance.High) { BuildEventContext = new BuildEventContext(1, 1, 1, 1) }); VerifyFileContent(log, "message here"); } finally @@ -474,7 +471,7 @@ private void VerifyFileContent(string file, string expectedContent) for (int i = 0; i < expectedLines.Length; i++) { - Assert.Equal(expectedLines[i].Trim(), actualLines[i].Trim()); + Assert.Contains(expectedLines[i].Trim(), actualLines[i].Trim()); } } diff --git a/src/Build.UnitTests/TerminalLoggerConfiguration_Tests.cs b/src/Build.UnitTests/TerminalLoggerConfiguration_Tests.cs index fae6fbcbeb6..5a7fe9c2b3d 100644 --- a/src/Build.UnitTests/TerminalLoggerConfiguration_Tests.cs +++ b/src/Build.UnitTests/TerminalLoggerConfiguration_Tests.cs @@ -91,7 +91,6 @@ public void TerminalLoggerWithTlAutoIsOff(string tlValue) TerminalLoggerUserIntent = tlValue, TerminalLoggerUserIntentSource = "arg", ConsoleLogger = true, - ConsoleLoggerType = "parallel", ConsoleLoggerVerbosity = "normal", FileLogger = false, }; @@ -206,7 +205,6 @@ public void TerminalLoggerDefaultOff(string defaultValue) TerminalLoggerUserIntentSource = null, ConsoleLogger = true, ConsoleLoggerVerbosity = "minimal", - ConsoleLoggerType = "parallel", FileLogger = false, }; diff --git a/src/Build/Logging/ConsoleLogger.cs b/src/Build/Logging/ConsoleLogger.cs index bffd841fcad..5f4a3ac5059 100644 --- a/src/Build/Logging/ConsoleLogger.cs +++ b/src/Build/Logging/ConsoleLogger.cs @@ -8,6 +8,7 @@ using Microsoft.Build.Framework.Telemetry; using Microsoft.Build.Shared; using BaseConsoleLogger = Microsoft.Build.BackEnd.Logging.BaseConsoleLogger; +using ParallelConsoleLogger = Microsoft.Build.BackEnd.Logging.ParallelConsoleLogger; #nullable disable @@ -145,14 +146,6 @@ private void InitializeBaseConsoleLogger() } _consoleLogger = new ParallelConsoleLogger(_verbosity, _write, _colorSet, _colorReset); - if (this is FileLogger) - { - KnownTelemetry.LoggingConfigurationTelemetry.FileLoggerType = "parallel"; - } - else - { - KnownTelemetry.LoggingConfigurationTelemetry.ConsoleLoggerType = "parallel"; - } if (_showSummary != null) { diff --git a/src/Build/Logging/FileLogger.cs b/src/Build/Logging/FileLogger.cs index b87504c5a54..537ea3c3540 100644 --- a/src/Build/Logging/FileLogger.cs +++ b/src/Build/Logging/FileLogger.cs @@ -88,7 +88,6 @@ private void InitializeFileLogger(IEventSource eventSource, int nodeCount) // Finally, ask the base console logger class to initialize. It may // want to make decisions based on our verbosity, so we do this last. base.Initialize(eventSource, nodeCount); - KnownTelemetry.LoggingConfigurationTelemetry.FileLoggersCount++; KnownTelemetry.LoggingConfigurationTelemetry.FileLogger = true; KnownTelemetry.LoggingConfigurationTelemetry.FileLoggerVerbosity = Verbosity.ToString(); diff --git a/src/Framework/Telemetry/LoggingConfigurationTelemetry.cs b/src/Framework/Telemetry/LoggingConfigurationTelemetry.cs index 9c721301747..9c222f06fc3 100644 --- a/src/Framework/Telemetry/LoggingConfigurationTelemetry.cs +++ b/src/Framework/Telemetry/LoggingConfigurationTelemetry.cs @@ -56,32 +56,16 @@ internal class LoggingConfigurationTelemetry : TelemetryBase /// public bool ConsoleLogger { get; set; } - /// - /// Type of console logger: serial | parallel - /// - public string? ConsoleLoggerType { get; set; } - /// /// Verbosity of console logger: quiet | minimal | normal | detailed | diagnostic /// public string? ConsoleLoggerVerbosity { get; set; } - /// /// True if file logger was used. /// public bool FileLogger { get; set; } - /// - /// Type of file logger: serial | parallel - /// - public string? FileLoggerType { get; set; } - - /// - /// Number of file loggers. - /// - public int FileLoggersCount { get; set; } - /// /// Verbosity of file logger: quiet | minimal | normal | detailed | diagnostic /// @@ -125,10 +109,6 @@ public override IDictionary GetProperties() } properties["ConsoleLogger"] = ConsoleLogger.ToString(CultureInfo.InvariantCulture); - if (ConsoleLoggerType != null) - { - properties["ConsoleLoggerType"] = ConsoleLoggerType; - } if (ConsoleLoggerVerbosity != null) { @@ -136,11 +116,6 @@ public override IDictionary GetProperties() } properties["FileLogger"] = FileLogger.ToString(CultureInfo.InvariantCulture); - if (FileLoggerType != null) - { - properties["FileLoggerType"] = FileLoggerType; - properties["FileLoggersCount"] = FileLoggersCount.ToString(CultureInfo.InvariantCulture); - } if (FileLoggerVerbosity != null) { diff --git a/src/MSBuild/XMake.cs b/src/MSBuild/XMake.cs index c36a0cabf52..dbf5e759dc5 100644 --- a/src/MSBuild/XMake.cs +++ b/src/MSBuild/XMake.cs @@ -1352,8 +1352,6 @@ internal static bool BuildProject( // Targeted perf optimization for the case where we only have our own parallel console logger, and verbosity is quiet. In such a case // we know we won't emit any messages except for errors and warnings, so the engine should not bother even logging them. - // If we're using the original serial console logger we can't do this, as it shows project started/finished context - // around errors and warnings. // Telling the engine to not bother logging non-critical messages means that typically it can avoid loading any resources in the successful // build case. if (loggers.Length == 1 && From 407d65ea7da87e7afd72caba225def2a48486271 Mon Sep 17 00:00:00 2001 From: YuliiaKovalova Date: Wed, 13 Aug 2025 17:30:34 +0200 Subject: [PATCH 3/4] update the comment --- src/Build/Logging/ConsoleLogger.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Build/Logging/ConsoleLogger.cs b/src/Build/Logging/ConsoleLogger.cs index 5f4a3ac5059..6769f05ddae 100644 --- a/src/Build/Logging/ConsoleLogger.cs +++ b/src/Build/Logging/ConsoleLogger.cs @@ -39,7 +39,7 @@ namespace Microsoft.Build.Logging /// /// This class implements the default logger that outputs event data /// to the console (stdout). - /// It is a facade: it creates, wraps and delegates to a kind of BaseConsoleLogger or ParallelConsoleLogger. + /// It is a facade: it creates, wraps and delegates to a kind of BaseConsoleLogger: ParallelConsoleLogger. /// /// This class is not thread safe. public class ConsoleLogger : INodeLogger From e4f5d9623dbf95046755dcbbb86129efe01da75f Mon Sep 17 00:00:00 2001 From: YuliiaKovalova Date: Tue, 19 Aug 2025 11:31:06 +0200 Subject: [PATCH 4/4] cleanup documentation --- documentation/wiki/CollectedTelemetry.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/documentation/wiki/CollectedTelemetry.md b/documentation/wiki/CollectedTelemetry.md index de290b12f15..19b09393edf 100644 --- a/documentation/wiki/CollectedTelemetry.md +++ b/documentation/wiki/CollectedTelemetry.md @@ -26,11 +26,8 @@ Expressed and collected via [LoggingConfigurationTelemetry type](https://github. | >= 8.0.100 | Default choice on terminal logger enablement. | | >= 8.0.100 | Source of default choice on terminal logger enablement. | | >= 8.0.100 | Indication if Console logger was used. | -| >= 8.0.100 | Console logger type (serial, parallel). | | >= 8.0.100 | Console logger verbosity. | | >= 8.0.100 | Indication if File logger was used. | -| >= 8.0.100 | File logger type (serial, parallel). | -| >= 8.0.100 | Number of file loggers. | | >= 8.0.100 | File logger verbosity. | | >= 8.0.100 | Indication if Binary logger was used. | | >= 8.0.100 | Indication if Binary logger used with default log name. |