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

Code before:
    private static bool IsBinaryLogger([NotNullWhen(returnValue: true)] ILogger? logger)
    {
        return logger?.GetType().FullName == "Microsoft.Build.Logging.BinaryLogger";
    }

    internal sealed class DefaultBinLogPathProvider : IBinLogPathProvider
    {
        internal const string DefaultFileName = "msbuild";
        internal 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 = !string.IsNullOrEmpty(Path.GetFileNameWithoutExtension(logFilePath))
                ? Path.GetFileNameWithoutExtension(logFilePath)!
                : DefaultFileName;
            _extension = !string.IsNullOrEmpty(Path.GetExtension(logFilePath))
                ? Path.GetExtension(logFilePath)!
                : DefaultExtension;
        }

        public string? GetNewLogPath() => BuildLogPath(_path, _filename, _extension, _suffix++);

        internal static string BuildLogPath(string path, string filename, string extension, int suffix)
        {
            return suffix == 0
                ? Path.Combine(path, filename + extension)
                : Path.Combine(path, $"{filename}-{suffix}{extension}");
        }
    }
}


Review comment (suggestion):
```suggestion
            _extension = Path.GetExtension(logFilePath) is { Length: > 0 } extension
                ? extension
                : DefaultExtension;
```

Code after:
    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)
                : Path.Combine(_directory, $"{_filename}-{suffix}{_extension}");

            return Path.GetFullPath(newPath);
        }
    }