Repository: dotnet/roslyn
File: src/Workspaces/MSBuild/Core/MSBuild/MSBuildProjectLoader.cs (C#)

Code before:
            this.LoadMetadataForReferencedProjects);

        return await worker.LoadAsync(cancellationToken).ConfigureAwait(false);
    }

    private static bool IsBinaryLogger([NotNullWhen(returnValue: true)] ILogger? logger)
    {
        // We validate the type name to avoid taking a dependency on the Microsoft.Build package.
        return logger?.GetType().FullName == "Microsoft.Build.Logging.BinaryLogger";
    }

    internal sealed class DefaultBinLogPathProvider : IBinLogPathProvider
    {
        private const string DefaultFileName = "msbuild";
        private const string DefaultExtension = ".binlog";

        private readonly string _path;
        private readonly string _filename;
        private readonly string _extension;
        private int _suffix = 0;

        public DefaultBinLogPathProvider(string logFilePath)
        {
            Contract.ThrowIfNull(logFilePath);

            _path = Path.GetDirectoryName(logFilePath) ?? ".";
            _filename = Path.GetFileNameWithoutExtension(logFilePath) is { Length: > 0 } fileName
                ? fileName
                : DefaultFileName;
            _extension = Path.GetExtension(logFilePath) is { Length: > 0 } extension
                ? extension
                : DefaultExtension;
        }

        public string? GetNewLogPath()
        {
            var newLogPath = _suffix == 0
                ? Path.Combine(_path, _filename + _extension)
                : Path.Combine(_path, $"{_filename}-{_suffix}{_extension}");

            _suffix++;
            return newLogPath;
        }
    }
}


Review comment (suggestion):
```suggestion
            _path = Path.GetDirectoryName(logFilePath) ?? Environment.CurrentDirectory;
```

My concern being that if we just use '.' we might have a surprise if the working directory of the build host is a different directory.

Code after:
            this.LoadMetadataForReferencedProjects);

        return await worker.LoadAsync(cancellationToken).ConfigureAwait(false);
    }

    private static bool IsBinaryLogger([NotNullWhen(returnValue: true)] ILogger? logger, out string? fileName)
    {
        // We validate the type name to avoid taking a dependency on the Microsoft.Build package
        // because it brings along additional dependencies and servicing requirements.
        if (logger?.GetType().FullName != "Microsoft.Build.Logging.BinaryLogger")
        {
            fileName = null;
            return false;
        }

        // The logger.Parameters could contain more than just the filename, such as "ProjectImports" or "OmitInitialInfo".
        // Attempt to get the parsed filname directly from the logger if possible.
        var fileNameProperty = logger.GetType().GetProperty("FileName");
        fileName = fileNameProperty?.GetValue(logger) as string ?? logger.Parameters;
        return true;
    }

    internal sealed class BinLogPathProvider : IBinLogPathProvider
    {
        private const string DefaultFileName = "msbuild";
        private const string DefaultExtension = ".binlog";

        private readonly string _directory;
        private readonly string _filename;
        private readonly string _extension;
        private int _suffix = -1;

        public BinLogPathProvider(string? logFilePath)
        {
            logFilePath ??= DefaultFileName + DefaultExtension;

            _directory = Path.GetDirectoryName(logFilePath) ?? ".";
            _filename = Path.GetFileNameWithoutExtension(logFilePath) is { Length: > 0 } fileName
                ? fileName
                : DefaultFileName;
            _extension = Path.GetExtension(logFilePath) is { Length: > 0 } extension
                ? extension
                : DefaultExtension;
        }

        public string? GetNewLogPath()
        {
            var suffix = Interlocked.Increment(ref _suffix);

            var newPath = suffix == 0
                ? Path.Combine(_directory, _filename + _extension)