@@ -306,7 +306,7 @@ private static bool TryParsePathParameter(string parameter, out string filePath)
306306 /// It should not be set by external code or logger implementations.
307307 /// Use multiple logger instances with different Parameters instead.
308308 /// </remarks>
309- public List < string > AdditionalFilePaths { get ; set ; }
309+ public IReadOnlyList < string > AdditionalFilePaths { get ; set ; }
310310
311311 /// <summary> Gets or sets the verbosity level.</summary>
312312 /// <remarks>
@@ -729,9 +729,11 @@ private static string ExpandPathParameter(string parameters)
729729 /// <returns>The resolved file path, or "msbuild.binlog" if no path is specified</returns>
730730 public static string ExtractFilePathFromParameters ( string parameters )
731731 {
732+ const string DefaultBinlogFileName = "msbuild" + BinlogFileExtension ;
733+
732734 if ( string . IsNullOrEmpty ( parameters ) )
733735 {
734- return Path . GetFullPath ( "msbuild.binlog" ) ;
736+ return Path . GetFullPath ( DefaultBinlogFileName ) ;
735737 }
736738
737739 var paramParts = parameters . Split ( MSBuildConstants . SemicolonChar , StringSplitOptions . RemoveEmptyEntries ) ;
@@ -748,7 +750,7 @@ public static string ExtractFilePathFromParameters(string parameters)
748750
749751 if ( filePath == null )
750752 {
751- filePath = "msbuild.binlog" ;
753+ filePath = DefaultBinlogFileName ;
752754 }
753755
754756 try
@@ -762,19 +764,25 @@ public static string ExtractFilePathFromParameters(string parameters)
762764 }
763765 }
764766
767+ /// <summary>
768+ /// Attempts to interpret a parameter string as a file path.
769+ /// </summary>
770+ /// <param name="parameter">The parameter to interpret (e.g., "LogFile=output.binlog" or "output.binlog")</param>
771+ /// <param name="filePath">The extracted file path if the parameter is a path, otherwise the original parameter</param>
772+ /// <returns>True if the parameter is a valid file path (ends with .binlog or contains wildcards), false otherwise</returns>
765773 private static bool TryInterpretPathParameterStatic ( string parameter , out string filePath )
766774 {
767- bool hasPathPrefix = parameter . StartsWith ( "LogFile=" , StringComparison . OrdinalIgnoreCase ) ;
775+ bool hasPathPrefix = parameter . StartsWith ( LogFileParameterPrefix , StringComparison . OrdinalIgnoreCase ) ;
768776
769777 if ( hasPathPrefix )
770778 {
771- parameter = parameter . Substring ( "LogFile=" . Length ) ;
779+ parameter = parameter . Substring ( LogFileParameterPrefix . Length ) ;
772780 }
773781
774782 parameter = parameter . Trim ( '"' ) ;
775783
776784 bool isWildcard = ChangeWaves . AreFeaturesEnabled ( ChangeWaves . Wave17_12 ) && parameter . Contains ( "{}" ) ;
777- bool hasProperExtension = parameter . EndsWith ( ".binlog" , StringComparison . OrdinalIgnoreCase ) ;
785+ bool hasProperExtension = parameter . EndsWith ( BinlogFileExtension , StringComparison . OrdinalIgnoreCase ) ;
778786 filePath = parameter ;
779787
780788 if ( ! isWildcard )
@@ -786,7 +794,7 @@ private static bool TryInterpretPathParameterStatic(string parameter, out string
786794
787795 if ( ! hasProperExtension )
788796 {
789- filePath += ".binlog" ;
797+ filePath += BinlogFileExtension ;
790798 }
791799 return true ;
792800 }
@@ -827,23 +835,39 @@ public static string ExtractNonPathParameters(string parameters)
827835 /// <summary>
828836 /// Result of processing multiple binary logger parameter sets.
829837 /// </summary>
830- public class ProcessedBinaryLoggerParameters
838+ public readonly struct ProcessedBinaryLoggerParameters
831839 {
832840 /// <summary>
833841 /// List of distinct parameter sets that need separate logger instances.
834842 /// </summary>
835- public List < string > DistinctParameterSets { get ; set ; } = new List < string > ( ) ;
843+ public IReadOnlyList < string > DistinctParameterSets { get ; }
836844
837845 /// <summary>
838846 /// If true, all parameter sets have identical configurations (only file paths differ),
839847 /// so a single logger can be used with file copying for additional paths.
840848 /// </summary>
841- public bool AllConfigurationsIdentical { get ; set ; } = true ;
849+ public bool AllConfigurationsIdentical { get ; }
842850
843851 /// <summary>
844852 /// Additional file paths to copy the binlog to (only valid when AllConfigurationsIdentical is true).
845853 /// </summary>
846- public List < string > AdditionalFilePaths { get ; set ; } = new List < string > ( ) ;
854+ public IReadOnlyList < string > AdditionalFilePaths { get ; }
855+
856+ /// <summary>
857+ /// Initializes a new instance of the <see cref="ProcessedBinaryLoggerParameters"/> struct.
858+ /// </summary>
859+ /// <param name="distinctParameterSets">List of distinct parameter sets that need separate logger instances.</param>
860+ /// <param name="allConfigurationsIdentical">Whether all parameter sets have identical configurations.</param>
861+ /// <param name="additionalFilePaths">Additional file paths to copy the binlog to.</param>
862+ public ProcessedBinaryLoggerParameters (
863+ IReadOnlyList < string > distinctParameterSets ,
864+ bool allConfigurationsIdentical ,
865+ IReadOnlyList < string > additionalFilePaths )
866+ {
867+ DistinctParameterSets = distinctParameterSets ;
868+ AllConfigurationsIdentical = allConfigurationsIdentical ;
869+ AdditionalFilePaths = additionalFilePaths ;
870+ }
847871 }
848872
849873 /// <summary>
@@ -853,17 +877,19 @@ public class ProcessedBinaryLoggerParameters
853877 /// <returns>Processed result with distinct parameter sets and configuration info</returns>
854878 public static ProcessedBinaryLoggerParameters ProcessParameters ( string [ ] binaryLoggerParameters )
855879 {
856- var result = new ProcessedBinaryLoggerParameters ( ) ;
880+ var distinctParameterSets = new List < string > ( ) ;
881+ var additionalFilePaths = new List < string > ( ) ;
882+ bool allConfigurationsIdentical = true ;
857883
858884 if ( binaryLoggerParameters == null || binaryLoggerParameters . Length == 0 )
859885 {
860- return result ;
886+ return new ProcessedBinaryLoggerParameters ( distinctParameterSets , allConfigurationsIdentical , additionalFilePaths ) ;
861887 }
862888
863889 if ( binaryLoggerParameters . Length == 1 )
864890 {
865- result . DistinctParameterSets . Add ( binaryLoggerParameters [ 0 ] ) ;
866- return result ;
891+ distinctParameterSets . Add ( binaryLoggerParameters [ 0 ] ) ;
892+ return new ProcessedBinaryLoggerParameters ( distinctParameterSets , allConfigurationsIdentical , additionalFilePaths ) ;
867893 }
868894
869895 string primaryArguments = binaryLoggerParameters [ 0 ] ;
@@ -883,22 +909,22 @@ public static ProcessedBinaryLoggerParameters ProcessParameters(string[] binaryL
883909 {
884910 if ( ! string . Equals ( primaryNonPathParams , currentNonPathParams , StringComparison . OrdinalIgnoreCase ) )
885911 {
886- result . AllConfigurationsIdentical = false ;
912+ allConfigurationsIdentical = false ;
887913 }
888- result . DistinctParameterSets . Add ( currentParams ) ;
914+ distinctParameterSets . Add ( currentParams ) ;
889915 }
890916 }
891917
892918 // If all configurations are identical, compute additional file paths for copying
893- if ( result . AllConfigurationsIdentical && result . DistinctParameterSets . Count > 1 )
919+ if ( allConfigurationsIdentical && distinctParameterSets . Count > 1 )
894920 {
895- for ( int i = 1 ; i < result . DistinctParameterSets . Count ; i ++ )
921+ for ( int i = 1 ; i < distinctParameterSets . Count ; i ++ )
896922 {
897- result . AdditionalFilePaths . Add ( ExtractFilePathFromParameters ( result . DistinctParameterSets [ i ] ) ) ;
923+ additionalFilePaths . Add ( ExtractFilePathFromParameters ( distinctParameterSets [ i ] ) ) ;
898924 }
899925 }
900926
901- return result ;
927+ return new ProcessedBinaryLoggerParameters ( distinctParameterSets , allConfigurationsIdentical , additionalFilePaths ) ;
902928 }
903929 }
904930}
0 commit comments