Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding log prefixkey to html logger #2204

Merged
merged 6 commits into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ public static class Constants
/// <summary>
/// Log file parameter key
/// </summary>
public const string LogFileNameKey = "LogFileName";
public const string LogFileNameKey = "LogFileName";

/// <summary>
/// Log file prefix parameter key
/// </summary>
public const string LogFilePrefixKey = "LogFilePrefix";

public static readonly TestProperty ExecutionIdProperty = TestProperty.Register("ExecutionId", ExecutionIdPropertyIdentifier, typeof(Guid), TestPropertyAttributes.Hidden, typeof(TestResult));

Expand Down
35 changes: 29 additions & 6 deletions src/Microsoft.TestPlatform.Extensions.HtmlLogger/HtmlLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger

using HtmlResource = Resources.Resources;
using HtmlLoggerConstants = Constants;
using NuGet.Frameworks;

/// <summary>
/// Logger for generating Html.
Expand Down Expand Up @@ -137,6 +138,14 @@ public void Initialize(TestLoggerEvents events, Dictionary<string, string> 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]);
}

Expand All @@ -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<string>();
}
Expand Down Expand Up @@ -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))
{
vagisha-nidhi marked this conversation as resolved.
Show resolved Hide resolved

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();
Expand Down Expand Up @@ -410,7 +433,7 @@ internal string GetFormattedDurationString(TimeSpan duration)
time.Add(duration.Milliseconds + "ms");
}
}
}
}

return time.Count == 0 ? "< 1ms" : string.Join(" ", time);
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,7 @@
<data name="HtmlLoggerError" xml:space="preserve">
<value>Html Logger Error : {0}</value>
</data>
<data name="PrefixAndNameProvidedError" xml:space="preserve">
<value>The parameters LogFileName and LogFilePrefix cannot be given together.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
<target state="new">Html Logger Error : {0}</target>
<note></note>
</trans-unit>
<trans-unit id="PrefixAndNameProvidedError">
<source>The parameters LogFileName and LogFilePrefix cannot be given together.</source>
<target state="new">The parameters LogFileName and LogFilePrefix cannot be given together.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
<target state="new">Html Logger Error : {0}</target>
<note></note>
</trans-unit>
<trans-unit id="PrefixAndNameProvidedError">
<source>The parameters LogFileName and LogFilePrefix cannot be given together.</source>
<target state="new">The parameters LogFileName and LogFilePrefix cannot be given together.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
<target state="new">Html Logger Error : {0}</target>
<note></note>
</trans-unit>
<trans-unit id="PrefixAndNameProvidedError">
<source>The parameters LogFileName and LogFilePrefix cannot be given together.</source>
<target state="new">The parameters LogFileName and LogFilePrefix cannot be given together.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
<target state="new">Html Logger Error : {0}</target>
<note></note>
</trans-unit>
<trans-unit id="PrefixAndNameProvidedError">
<source>The parameters LogFileName and LogFilePrefix cannot be given together.</source>
<target state="new">The parameters LogFileName and LogFilePrefix cannot be given together.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
<target state="new">Html Logger Error : {0}</target>
<note></note>
</trans-unit>
<trans-unit id="PrefixAndNameProvidedError">
<source>The parameters LogFileName and LogFilePrefix cannot be given together.</source>
<target state="new">The parameters LogFileName and LogFilePrefix cannot be given together.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
<target state="new">Html Logger Error : {0}</target>
<note></note>
</trans-unit>
<trans-unit id="PrefixAndNameProvidedError">
<source>The parameters LogFileName and LogFilePrefix cannot be given together.</source>
<target state="new">The parameters LogFileName and LogFilePrefix cannot be given together.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
<target state="new">Html Logger Error : {0}</target>
<note></note>
</trans-unit>
<trans-unit id="PrefixAndNameProvidedError">
<source>The parameters LogFileName and LogFilePrefix cannot be given together.</source>
<target state="new">The parameters LogFileName and LogFilePrefix cannot be given together.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
<target state="new">Html Logger Error : {0}</target>
<note></note>
</trans-unit>
<trans-unit id="PrefixAndNameProvidedError">
<source>The parameters LogFileName and LogFilePrefix cannot be given together.</source>
<target state="new">The parameters LogFileName and LogFilePrefix cannot be given together.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
<target state="new">Html Logger Error : {0}</target>
<note></note>
</trans-unit>
<trans-unit id="PrefixAndNameProvidedError">
<source>The parameters LogFileName and LogFilePrefix cannot be given together.</source>
<target state="new">The parameters LogFileName and LogFilePrefix cannot be given together.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
<target state="new">Html Logger Error : {0}</target>
<note></note>
</trans-unit>
<trans-unit id="PrefixAndNameProvidedError">
<source>The parameters LogFileName and LogFilePrefix cannot be given together.</source>
<target state="new">The parameters LogFileName and LogFilePrefix cannot be given together.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
<target state="new">Html Logger Error : {0}</target>
<note></note>
</trans-unit>
<trans-unit id="PrefixAndNameProvidedError">
<source>The parameters LogFileName and LogFilePrefix cannot be given together.</source>
<target state="new">The parameters LogFileName and LogFilePrefix cannot be given together.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
<target state="new">Html Logger Error : {0}</target>
<note></note>
</trans-unit>
<trans-unit id="PrefixAndNameProvidedError">
<source>The parameters LogFileName and LogFilePrefix cannot be given together.</source>
<target state="new">The parameters LogFileName and LogFilePrefix cannot be given together.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
<target state="new">Html Logger Error : {0}</target>
<note></note>
</trans-unit>
<trans-unit id="PrefixAndNameProvidedError">
<source>The parameters LogFileName and LogFilePrefix cannot be given together.</source>
<target state="new">The parameters LogFileName and LogFilePrefix cannot be given together.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
<target state="new">Html Logger Error : {0}</target>
<note></note>
</trans-unit>
<trans-unit id="PrefixAndNameProvidedError">
<source>The parameters LogFileName and LogFilePrefix cannot be given together.</source>
<target state="new">The parameters LogFileName and LogFilePrefix cannot be given together.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
11 changes: 7 additions & 4 deletions src/Microsoft.TestPlatform.Extensions.TrxLogger/TrxLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -489,12 +489,15 @@ private void DeriveTrxFilePath()
{
if (!string.IsNullOrWhiteSpace(logFilePrefixValue))
{
var framework = this.parametersDictionary[DefaultLoggerParameterNames.TargetFramework] ?? string.Empty;
framework = NuGetFramework.Parse(framework).GetShortFolderName();
var framework = this.parametersDictionary[DefaultLoggerParameterNames.TargetFramework];
if (framework != null)
{
framework = NuGetFramework.Parse(framework).GetShortFolderName();
logFilePrefixValue = logFilePrefixValue + "_" + framework;
}

logFilePrefixValue = logFilePrefixValue.Replace(".trx", string.Empty) + "_" + framework + DateTime.Now.ToString("_yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo) + this.trxFileExtension;
logFilePrefixValue = logFilePrefixValue + DateTime.Now.ToString("_yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo) + this.trxFileExtension;
this.trxFilePath = Path.Combine(this.testResultsDirPath, logFilePrefixValue);

return;
}
}
Expand Down
Loading