Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Compilers/Core/MSBuildTask/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<Compile Include="$(MSBuildThisFileDirectory)PropertyDictionary.cs" />
<Compile Include="$(MSBuildThisFileDirectory)RCWForCurrentContext.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ShowMessageForImplicitlySkipAnalyzers.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TaskCompilerServerLogger.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Utilities.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ValidateBootstrap.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Vbc.cs" />
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/Core/MSBuildTask/ManagedCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,8 @@ public string GeneratePathToTool()

protected override int ExecuteTool(string pathToTool, string responseFileCommands, string commandLineCommands)
{
using var logger = new CompilerServerLogger($"MSBuild {Process.GetCurrentProcess().Id}");
using var innerLogger = new CompilerServerLogger($"MSBuild {Process.GetCurrentProcess().Id}");
var logger = new TaskCompilerServerLogger(Log, innerLogger);
return ExecuteTool(pathToTool, responseFileCommands, commandLineCommands, logger);
}

Expand Down Expand Up @@ -818,7 +819,6 @@ private void LogCompilationMessage(ICompilerServerLogger logger, string requestI
else
{
logger.Log(message);
Log.LogMessage(message);
}
}

Expand Down
28 changes: 28 additions & 0 deletions src/Compilers/Core/MSBuildTask/TaskCompilerServerLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.Build.Utilities;
using Microsoft.CodeAnalysis.CommandLine;

namespace Microsoft.CodeAnalysis.BuildTasks;

/// <summary>
/// Logs to both the MSBuild task's output and the inner compiler server logger.
/// </summary>
internal sealed class TaskCompilerServerLogger(
TaskLoggingHelper taskLogger,
ICompilerServerLogger inner)
: ICompilerServerLogger
{
private readonly TaskLoggingHelper _taskLogger = taskLogger;
private readonly ICompilerServerLogger _inner = inner;

public bool IsLogging => true;

public void Log(string message)
{
_inner.Log(message);
_taskLogger.LogMessage(message);
}
}
3 changes: 1 addition & 2 deletions src/Compilers/Shared/CompilerServerLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ internal sealed class CompilerServerLogger : ICompilerServerLogger, IDisposable
{
// Environment variable, if set, to enable logging and set the file to log to.
internal const string EnvironmentVariableName = "RoslynCommandLineLogFile";
internal const string LoggingPrefix = "---";

private Stream? _loggingStream;
private readonly string _identifier;
Expand Down Expand Up @@ -152,7 +151,7 @@ public void Log(string message)
if (_loggingStream is object)
{
var threadId = Environment.CurrentManagedThreadId;
var prefix = $"ID={_identifier} TID={threadId}: ";
var prefix = $"[{DateTimeOffset.Now:o}] ID={_identifier} TID={threadId}: ";
string output = prefix + message + Environment.NewLine;
byte[] bytes = Encoding.UTF8.GetBytes(output);

Expand Down