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
5 changes: 4 additions & 1 deletion src/Compilers/Server/VBCSCompiler/VBCSCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ public static int Main(string[] args)
return CommonCompiler.Failed;
}

using var logger = new CompilerServerLogger($"VBCSCompiler {Process.GetCurrentProcess().Id}", options.LogFilePath);
var identifier = $"VBCSCompiler {Process.GetCurrentProcess().Id}";
using var logger = options.LogFilePath is null

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: personally, I'd prefer inlining the ternary into the argument, rather than duplicating the entire constructor call, but up to you if you address this or won't fix.

@jjonescz jjonescz Sep 9, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, we can't inline since it needs to call a different overload, but I should at least share the other argument expression. Thanks.

? new CompilerServerLogger(identifier, StandardBuildEnvironment.Instance)
: new CompilerServerLogger(identifier, options.LogFilePath);

#if BOOTSTRAP
ExitingTraceListener.Install(logger);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,65 @@ public void Dispose()

public class StartupTests : VBCSCompilerServerTests
{
[Theory]
[InlineData(false)]
[InlineData(true)]
public void LoggingFromEnvironment(bool logToDirectory)
{
var directory = TempRoot.CreateDirectory();
var logPath = logToDirectory ? directory.Path : Path.Combine(directory.Path, "server.log");

RunServerWithLogging(logPath);

var logFile = Assert.Single(Directory.GetFiles(directory.Path));
if (logToDirectory)
{
Assert.StartsWith("server.", Path.GetFileName(logFile));
Assert.EndsWith(".log", logFile);
}
else
{
Assert.Equal(logPath, logFile);
}

var log = File.ReadAllText(logFile);
Assert.Contains("ID=VBCSCompiler ", log);
Assert.Contains("Keep alive timeout is: 1000 milliseconds.", log);
}

[Fact]
public void ExplicitLogFileOverridesEnvironment()
{
var directory = TempRoot.CreateDirectory();
var environmentLogPath = Path.Combine(directory.Path, "environment.log");
var explicitLogPath = Path.Combine(directory.Path, "explicit.log");

RunServerWithLogging(environmentLogPath, $@" -log:""{explicitLogPath}""");

Assert.False(File.Exists(environmentLogPath));
var log = File.ReadAllText(explicitLogPath);
Assert.Contains("ID=VBCSCompiler ", log);
Assert.Contains("Keep alive timeout is: 1000 milliseconds.", log);
}

private static void RunServerWithLogging(string environmentLogPath, string additionalArguments = "")
{
var filePath = typeof(VBCSCompiler).Assembly.Location;
var arguments = $"-pipename:{ServerUtil.GetPipeName()} -timeout:1{additionalArguments}";
if (BuildServerConnection.IsBuiltinToolRunningOnCoreClr)
{
arguments = RuntimeHostInfo.GetDotNetExecCommandLine(filePath, arguments);
filePath = RuntimeHostInfo.GetDotNetHostPath(StandardBuildEnvironment.Instance);
}

var result = ProcessUtilities.Run(filePath, arguments, additionalEnvironmentVars:
new Dictionary<string, string>
{
[CompilerServerLogger.EnvironmentVariableName] = environmentLogPath,
});
Assert.True(result.ExitCode == CommonCompiler.Succeeded, result.ToString());
}

[ConditionalFact(typeof(WindowsOnly))]
[WorkItem(217709, "https://devdiv.visualstudio.com/DevDiv/_workitems/edit/217709")]
public async Task ShadowCopyAnalyzerAssemblyLoaderMissingDirectory()
Expand Down
Loading