@@ -22,6 +22,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger
22
22
23
23
using HtmlResource = Resources . Resources ;
24
24
using HtmlLoggerConstants = Constants ;
25
+ using NuGet . Frameworks ;
25
26
26
27
/// <summary>
27
28
/// Logger for generating Html.
@@ -137,6 +138,14 @@ public void Initialize(TestLoggerEvents events, Dictionary<string, string> param
137
138
}
138
139
139
140
parametersDictionary = parameters ;
141
+
142
+ if ( parameters . TryGetValue ( HtmlLoggerConstants . LogFilePrefixKey , out string logFilePrefixValue ) && parameters . TryGetValue ( HtmlLoggerConstants . LogFileNameKey , out string logFileNameValue ) )
143
+ {
144
+ var htmlParameterErrorMsg = string . Format ( CultureInfo . CurrentCulture , HtmlResource . PrefixAndNameProvidedError ) ;
145
+ EqtTrace . Error ( htmlParameterErrorMsg ) ;
146
+ throw new ArgumentException ( htmlParameterErrorMsg ) ;
147
+ }
148
+
140
149
this . Initialize ( events , parameters [ DefaultLoggerParameterNames . TestRunDirectory ] ) ;
141
150
}
142
151
@@ -153,7 +162,7 @@ public void TestMessageHandler(object sender, TestRunMessageEventArgs e)
153
162
switch ( e . Level )
154
163
{
155
164
case TestMessageLevel . Informational :
156
- if ( TestRunDetails . RunLevelMessageInformational == null )
165
+ if ( TestRunDetails . RunLevelMessageInformational == null )
157
166
{
158
167
TestRunDetails . RunLevelMessageInformational = new List < string > ( ) ;
159
168
}
@@ -273,11 +282,25 @@ public void TestRunCompleteHandler(object sender, TestRunCompleteEventArgs e)
273
282
PassPercentage = ( PassedTests * 100 ) / TotalTests ,
274
283
TotalRunTime = GetFormattedDurationString ( e . ElapsedTimeInRunningTests ) ,
275
284
} ;
276
- var isLogFileNameParameterExists = parametersDictionary . TryGetValue ( HtmlLoggerConstants . LogFileNameKey ,
277
- out string logFileNameValue ) ;
278
- if ( isLogFileNameParameterExists && ! string . IsNullOrWhiteSpace ( logFileNameValue ) )
285
+ if ( this . parametersDictionary . TryGetValue ( HtmlLoggerConstants . LogFilePrefixKey , out string logFilePrefixValue ) && ! string . IsNullOrWhiteSpace ( logFilePrefixValue ) )
286
+ {
287
+
288
+ var framework = this . parametersDictionary [ DefaultLoggerParameterNames . TargetFramework ] ;
289
+ if ( framework != null )
290
+ {
291
+ framework = NuGetFramework . Parse ( framework ) . GetShortFolderName ( ) ;
292
+ logFilePrefixValue = logFilePrefixValue + "_" + framework ;
293
+ }
294
+
295
+ logFilePrefixValue = logFilePrefixValue + DateTime . Now . ToString ( "_yyyyMMddHHmmss" , DateTimeFormatInfo . InvariantInfo ) + $ ".{ HtmlLoggerConstants . HtmlFileExtension } ";
296
+ this . HtmlFilePath = Path . Combine ( TestResultsDirPath , logFilePrefixValue ) ;
297
+ }
298
+ else
279
299
{
280
- HtmlFilePath = Path . Combine ( TestResultsDirPath , logFileNameValue ) ;
300
+ if ( parametersDictionary . TryGetValue ( HtmlLoggerConstants . LogFileNameKey , out string logFileNameValue ) && ! string . IsNullOrWhiteSpace ( logFileNameValue ) )
301
+ {
302
+ this . HtmlFilePath = Path . Combine ( TestResultsDirPath , logFileNameValue ) ;
303
+ }
281
304
}
282
305
283
306
PopulateHtmlFile ( ) ;
@@ -410,7 +433,7 @@ internal string GetFormattedDurationString(TimeSpan duration)
410
433
time . Add ( duration . Milliseconds + "ms" ) ;
411
434
}
412
435
}
413
- }
436
+ }
414
437
415
438
return time . Count == 0 ? "< 1ms" : string . Join ( " " , time ) ;
416
439
}
0 commit comments