Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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);
}
}
6 changes: 3 additions & 3 deletions src/Compilers/Server/VBCSCompiler/VBCSCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
// 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.CodeAnalysis.CommandLine;
using System;
using System.Collections.Specialized;
using System.IO;
using System.Diagnostics;
using Microsoft.CodeAnalysis.CommandLine;

namespace Microsoft.CodeAnalysis.CompilerServer
{
internal static class VBCSCompiler
{
public static int Main(string[] args)
{
using var logger = new CompilerServerLogger("VBCSCompiler");
using var logger = new CompilerServerLogger($"VBCSCompiler {Process.GetCurrentProcess().Id}");

NameValueCollection appSettings;
try
Expand Down
5 changes: 3 additions & 2 deletions src/Compilers/Shared/BuildServerConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,8 @@ internal static bool TryCreateServer(string clientDirectory, string pipeName, IC
return false;
}

logger.Log("Attempting to create process '{0}' {1}", serverInfo.processFilePath, serverInfo.commandLineArguments);

if (PlatformInformation.IsWindows)
{
// As far as I can tell, there isn't a way to use the Process class to
Expand All @@ -476,8 +478,6 @@ internal static bool TryCreateServer(string clientDirectory, string pipeName, IC

PROCESS_INFORMATION processInfo;

logger.Log("Attempting to create process '{0}'", serverInfo.processFilePath);

var builder = new StringBuilder($@"""{serverInfo.processFilePath}"" {serverInfo.commandLineArguments}");

bool success = CreateProcess(
Expand Down Expand Up @@ -524,6 +524,7 @@ internal static bool TryCreateServer(string clientDirectory, string pipeName, IC
if (Process.Start(startInfo) is { } process)
{
processId = process.Id;
logger.Log("Successfully created process with process id {0}", processId);
return true;
}
else
Expand Down
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
Loading