Skip to content

Commit f93b24b

Browse files
Revert "Added support for logging interpolated strings in tasks. (#8424)" (#8479)
This reverts commit 05f741b, which should unblock dotnet/installer#15586.
1 parent 4b5e303 commit f93b24b

File tree

4 files changed

+1
-206
lines changed

4 files changed

+1
-206
lines changed

src/Framework/LogInterpolatedStringHandler.cs

Lines changed: 0 additions & 88 deletions
This file was deleted.

src/Shared/TaskLoggingHelper.cs

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public virtual string GetResourceMessage(string resourceName)
239239
}
240240
#endregion
241241

242-
#region Message logging method
242+
#region Message logging methods
243243

244244
/// <summary>
245245
/// Returns <see langword="true"/> if the build is configured to log all task inputs.
@@ -258,33 +258,6 @@ public bool LogsMessagesOfImportance(MessageImportance importance)
258258
|| buildEngine10.EngineServices.LogsMessagesOfImportance(importance);
259259
}
260260

261-
#if NET6_0_OR_GREATER
262-
263-
/// <summary>
264-
/// Logs a message using the specified interpolated string.
265-
/// Thread safe.
266-
/// </summary>
267-
/// <param name="stringHandler">The message interpolated string.</param>
268-
public void LogMessage(LogInterpolatedStringHandler stringHandler)
269-
{
270-
LogMessage(MessageImportance.Normal, stringHandler);
271-
}
272-
273-
/// <summary>
274-
/// Logs a message using the specified interpolated string.
275-
/// Thread safe.
276-
/// </summary>
277-
/// <param name="importance">The importance level of the message.</param>
278-
/// <param name="stringHandler">The message interpolated string.</param>
279-
public void LogMessage(MessageImportance importance, LogInterpolatedStringHandler stringHandler)
280-
{
281-
if (LogsMessagesOfImportance(importance))
282-
{
283-
LogMessage(importance, stringHandler.GetFormat(), stringHandler.Arguments);
284-
}
285-
}
286-
#endif
287-
288261
/// <summary>
289262
/// Logs a message using the specified string.
290263
/// Thread safe.
@@ -620,19 +593,6 @@ public void LogCommandLine(MessageImportance importance, string commandLine)
620593

621594
#region Error logging methods
622595

623-
#if NET6_0_OR_GREATER
624-
625-
/// <summary>
626-
/// Logs an error message using the specified interpolated string.
627-
/// Thread safe.
628-
/// </summary>
629-
/// <param name="stringHandler">The message interpolated string.</param>
630-
public void LogError(LogInterpolatedStringHandler stringHandler)
631-
{
632-
LogError(stringHandler.GetFormat(), stringHandler.Arguments);
633-
}
634-
#endif
635-
636596
/// <summary>
637597
/// Logs an error using the specified string.
638598
/// Thread safe.
@@ -984,19 +944,6 @@ public void LogErrorFromException(Exception exception, bool showStackTrace, bool
984944

985945
#region Warning logging methods
986946

987-
#if NET6_0_OR_GREATER
988-
989-
/// <summary>
990-
/// Logs a warning message using the specified interpolated string.
991-
/// Thread safe.
992-
/// </summary>
993-
/// <param name="stringHandler">The message interpolated string.</param>
994-
public void LogWarning(LogInterpolatedStringHandler stringHandler)
995-
{
996-
LogWarning(stringHandler.GetFormat(), stringHandler.Arguments);
997-
}
998-
#endif
999-
1000947
/// <summary>
1001948
/// Logs a warning using the specified string.
1002949
/// Thread safe.

src/Utilities.UnitTests/MockEngine.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ internal sealed class MockEngine : IBuildEngine3
3131
{
3232
private StringBuilder _log = new StringBuilder();
3333

34-
public List<LazyFormattedBuildEventArgs> BuildEventArgs { get; } = new List<LazyFormattedBuildEventArgs>();
35-
3634
public MessageImportance MinimumMessageImportance { get; set; } = MessageImportance.Low;
3735

3836
internal int Messages { set; get; }
@@ -45,17 +43,13 @@ internal sealed class MockEngine : IBuildEngine3
4543

4644
public void LogErrorEvent(BuildErrorEventArgs eventArgs)
4745
{
48-
BuildEventArgs.Add(eventArgs);
49-
5046
Console.WriteLine(EventArgsFormatting.FormatEventMessage(eventArgs));
5147
_log.AppendLine(EventArgsFormatting.FormatEventMessage(eventArgs));
5248
++Errors;
5349
}
5450

5551
public void LogWarningEvent(BuildWarningEventArgs eventArgs)
5652
{
57-
BuildEventArgs.Add(eventArgs);
58-
5953
Console.WriteLine(EventArgsFormatting.FormatEventMessage(eventArgs));
6054
_log.AppendLine(EventArgsFormatting.FormatEventMessage(eventArgs));
6155
++Warnings;
@@ -72,8 +66,6 @@ public void LogMessageEvent(BuildMessageEventArgs eventArgs)
7266
// Only if the message is above the minimum importance should we record the log message
7367
if (eventArgs.Importance <= MinimumMessageImportance)
7468
{
75-
BuildEventArgs.Add(eventArgs);
76-
7769
Console.WriteLine(eventArgs.Message);
7870
_log.AppendLine(eventArgs.Message);
7971
++Messages;

src/Utilities.UnitTests/TaskLoggingHelper_Tests.cs

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System;
5-
using System.Collections.Generic;
65
using System.IO;
7-
using System.Linq;
8-
using System.Linq.Expressions;
9-
using System.Reflection;
106
using Microsoft.Build.Exceptions;
117
using Microsoft.Build.Framework;
128
using Microsoft.Build.Shared;
@@ -314,57 +310,5 @@ public void TestLogFromExceptionWithAggregateException()
314310
engine.AssertLogContains("The operation was invalid");
315311
engine.AssertLogContains("An I/O error occurred");
316312
}
317-
318-
#if NET6_0_OR_GREATER
319-
320-
public static IEnumerable<object[]> InterpolatedLogTestData()
321-
{
322-
Action<Task> logMessage = t => t.Log.LogMessage($"echo {0} and {"1"} {2} {3} {4} {5} {6} {7} {8} {9} {10}");
323-
Action<Task> logWarning = t => t.Log.LogWarning($"echo {0} and {"1"}");
324-
Action<Task> logError = t => t.Log.LogError($"echo {0} and {"1"}");
325-
326-
yield return new object[] { logMessage, "echo 0 and 1 2 3 4 5 6 7 8 9 10", typeof(BuildMessageEventArgs) };
327-
yield return new object[] { logWarning, "echo 0 and 1", typeof(BuildWarningEventArgs) };
328-
yield return new object[] { logError, "echo 0 and 1", typeof(BuildErrorEventArgs) };
329-
}
330-
331-
[Theory]
332-
[MemberData(nameof(InterpolatedLogTestData))]
333-
public void LogWithInterpolatedString(Action<Task> logAction, string expectedResult, Type expectedEventType)
334-
{
335-
MockEngine mockEngine = new MockEngine();
336-
Task t = new MockTask();
337-
t.BuildEngine = mockEngine;
338-
339-
logAction(t);
340-
341-
mockEngine.BuildEventArgs.Count.ShouldBe(1);
342-
mockEngine.BuildEventArgs[0].ShouldBeOfType(expectedEventType);
343-
mockEngine.BuildEventArgs[0].Message.ShouldBe(expectedResult);
344-
345-
MethodBody logActionBody = logAction
346-
.GetMethodInfo()
347-
.GetMethodBody();
348-
349-
logActionBody
350-
.LocalVariables
351-
.Select(lvi => lvi.LocalType)
352-
.ShouldContain(typeof(LogInterpolatedStringHandler), "Wrong logging method was bound");
353-
}
354-
355-
[Fact]
356-
public void LogMessageWithInterpolatedString_RespectsImportanceLevel()
357-
{
358-
MockEngine mockEngine = new MockEngine();
359-
Task t = new MockTask();
360-
t.BuildEngine = mockEngine;
361-
362-
mockEngine.MinimumMessageImportance = MessageImportance.High;
363-
t.Log.LogMessage(MessageImportance.Low, $"echo {0} and {"1"}");
364-
365-
mockEngine.BuildEventArgs.Count.ShouldBe(0);
366-
}
367-
#endif
368-
369313
}
370314
}

0 commit comments

Comments
 (0)