diff --git a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Constants.cs b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Constants.cs
index fb91883432..1c0ac5394e 100644
--- a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Constants.cs
+++ b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Constants.cs
@@ -51,7 +51,12 @@ public static class Constants
///
/// Log file parameter key
///
- public const string LogFileNameKey = "LogFileName";
+ public const string LogFileNameKey = "LogFileName";
+
+ ///
+ /// Log file prefix parameter key
+ ///
+ public const string LogFilePrefixKey = "LogFilePrefix";
public static readonly TestProperty ExecutionIdProperty = TestProperty.Register("ExecutionId", ExecutionIdPropertyIdentifier, typeof(Guid), TestPropertyAttributes.Hidden, typeof(TestResult));
diff --git a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/HtmlLogger.cs b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/HtmlLogger.cs
index 482f9408b0..4523f7519e 100644
--- a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/HtmlLogger.cs
+++ b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/HtmlLogger.cs
@@ -22,6 +22,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger
using HtmlResource = Resources.Resources;
using HtmlLoggerConstants = Constants;
+ using NuGet.Frameworks;
///
/// Logger for generating Html.
@@ -137,6 +138,14 @@ public void Initialize(TestLoggerEvents events, Dictionary param
}
parametersDictionary = parameters;
+
+ if (parameters.TryGetValue(HtmlLoggerConstants.LogFilePrefixKey, out string logFilePrefixValue) && parameters.TryGetValue(HtmlLoggerConstants.LogFileNameKey, out string logFileNameValue))
+ {
+ var htmlParameterErrorMsg = string.Format(CultureInfo.CurrentCulture, HtmlResource.PrefixAndNameProvidedError);
+ EqtTrace.Error(htmlParameterErrorMsg);
+ throw new ArgumentException(htmlParameterErrorMsg);
+ }
+
this.Initialize(events, parameters[DefaultLoggerParameterNames.TestRunDirectory]);
}
@@ -153,7 +162,7 @@ public void TestMessageHandler(object sender, TestRunMessageEventArgs e)
switch (e.Level)
{
case TestMessageLevel.Informational:
- if(TestRunDetails.RunLevelMessageInformational == null)
+ if (TestRunDetails.RunLevelMessageInformational == null)
{
TestRunDetails.RunLevelMessageInformational = new List();
}
@@ -273,11 +282,25 @@ public void TestRunCompleteHandler(object sender, TestRunCompleteEventArgs e)
PassPercentage = (PassedTests * 100) / TotalTests,
TotalRunTime = GetFormattedDurationString(e.ElapsedTimeInRunningTests),
};
- var isLogFileNameParameterExists = parametersDictionary.TryGetValue(HtmlLoggerConstants.LogFileNameKey,
- out string logFileNameValue);
- if (isLogFileNameParameterExists && !string.IsNullOrWhiteSpace(logFileNameValue))
+ if (this.parametersDictionary.TryGetValue(HtmlLoggerConstants.LogFilePrefixKey, out string logFilePrefixValue) && !string.IsNullOrWhiteSpace(logFilePrefixValue))
+ {
+
+ var framework = this.parametersDictionary[DefaultLoggerParameterNames.TargetFramework];
+ if (framework != null)
+ {
+ framework = NuGetFramework.Parse(framework).GetShortFolderName();
+ logFilePrefixValue = logFilePrefixValue + "_" + framework;
+ }
+
+ logFilePrefixValue = logFilePrefixValue + DateTime.Now.ToString("_yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo) + $".{HtmlLoggerConstants.HtmlFileExtension}";
+ this.HtmlFilePath = Path.Combine(TestResultsDirPath, logFilePrefixValue);
+ }
+ else
{
- HtmlFilePath = Path.Combine(TestResultsDirPath, logFileNameValue);
+ if (parametersDictionary.TryGetValue(HtmlLoggerConstants.LogFileNameKey, out string logFileNameValue) && !string.IsNullOrWhiteSpace(logFileNameValue))
+ {
+ this.HtmlFilePath = Path.Combine(TestResultsDirPath, logFileNameValue);
+ }
}
PopulateHtmlFile();
@@ -410,7 +433,7 @@ internal string GetFormattedDurationString(TimeSpan duration)
time.Add(duration.Milliseconds + "ms");
}
}
- }
+ }
return time.Count == 0 ? "< 1ms" : string.Join(" ", time);
}
diff --git a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Resources/Resources.Designer.cs b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Resources/Resources.Designer.cs
index 9c2bc33784..4c39a8ad6e 100644
--- a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Resources/Resources.Designer.cs
+++ b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Resources/Resources.Designer.cs
@@ -19,7 +19,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Resources {
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
@@ -77,5 +77,14 @@ internal static string HtmlLoggerError {
return ResourceManager.GetString("HtmlLoggerError", resourceCulture);
}
}
+
+ ///
+ /// Looks up a localized string similar to The parameters LogFileName and LogFilePrefix cannot be given together..
+ ///
+ internal static string PrefixAndNameProvidedError {
+ get {
+ return ResourceManager.GetString("PrefixAndNameProvidedError", resourceCulture);
+ }
+ }
}
}
diff --git a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Resources/Resources.resx b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Resources/Resources.resx
index a176fb3154..8182657a80 100644
--- a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Resources/Resources.resx
+++ b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Resources/Resources.resx
@@ -123,4 +123,7 @@
Html Logger Error : {0}
+
+ The parameters LogFileName and LogFilePrefix cannot be given together.
+
\ No newline at end of file
diff --git a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Resources/xlf/Resources.cs.xlf b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Resources/xlf/Resources.cs.xlf
index e2c74fb485..9c35d137af 100644
--- a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Resources/xlf/Resources.cs.xlf
+++ b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Resources/xlf/Resources.cs.xlf
@@ -30,6 +30,11 @@
Html Logger Error : {0}
+
+ The parameters LogFileName and LogFilePrefix cannot be given together.
+ The parameters LogFileName and LogFilePrefix cannot be given together.
+
+