Skip to content

Commit

Permalink
Forward logs to EqtTrace on netcore (#776)
Browse files Browse the repository at this point in the history
  • Loading branch information
nohwnd authored Feb 17, 2021
1 parent 9d92f65 commit 956f367
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/Adapter/MSTest.CoreAdapter/MSTestExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public MSTestExecutor()

public void RunTests(IEnumerable<TestCase> tests, IRunContext runContext, IFrameworkHandle frameworkHandle)
{
PlatformServiceProvider.Instance.AdapterTraceLogger.LogInfo("MSTestExecutor.RunTests: Running tests from testcases.");

ValidateArg.NotNull(frameworkHandle, "frameworkHandle");
ValidateArg.NotNullOrEmpty(tests, "tests");

Expand Down Expand Up @@ -76,6 +78,7 @@ public void RunTests(IEnumerable<TestCase> tests, IRunContext runContext, IFrame

public void RunTests(IEnumerable<string> sources, IRunContext runContext, IFrameworkHandle frameworkHandle)
{
PlatformServiceProvider.Instance.AdapterTraceLogger.LogInfo("MSTestExecutor.RunTests: Running tests from sources.");
ValidateArg.NotNull(frameworkHandle, "frameworkHandle");
ValidateArg.NotNullOrEmpty(sources, "sources");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ public class AdapterTraceLogger : IAdapterTraceLogger
/// <param name="args"> The args. </param>
public void LogError(string format, params object[] args)
{
EqtTrace.ErrorIf(EqtTrace.IsErrorEnabled, format, args);
if (EqtTrace.IsErrorEnabled)
{
EqtTrace.Error(this.PrependAdapterName(format, args));
}
}

/// <summary>
Expand All @@ -30,7 +33,10 @@ public void LogError(string format, params object[] args)
/// <param name="args"> The args. </param>
public void LogWarning(string format, params object[] args)
{
EqtTrace.WarningIf(EqtTrace.IsWarningEnabled, format, args);
if (EqtTrace.IsWarningEnabled)
{
EqtTrace.Warning(this.PrependAdapterName(format, args));
}
}

/// <summary>
Expand All @@ -40,7 +46,15 @@ public void LogWarning(string format, params object[] args)
/// <param name="args"> The args. </param>
public void LogInfo(string format, params object[] args)
{
EqtTrace.InfoIf(EqtTrace.IsInfoEnabled, format, args);
if (EqtTrace.IsInfoEnabled)
{
EqtTrace.Info(this.PrependAdapterName(format, args));
}
}

private string PrependAdapterName(string format, params object[] args)
{
return string.Format($"MSTest - {string.Format(format, args)}");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices
{
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;

#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName

Expand All @@ -17,32 +18,43 @@ public class AdapterTraceLogger : IAdapterTraceLogger
/// </summary>
/// <param name="format"> The format. </param>
/// <param name="args"> The args. </param>
/// <exception cref="System.NotImplementedException"> This is currently not implemented. </exception>
public void LogError(string format, params object[] args)
{
// Do Nothing.
if (EqtTrace.IsErrorEnabled)
{
EqtTrace.Error(this.PrependAdapterName(format, args));
}
}

/// <summary>
/// Log a warning in a given format.
/// </summary>
/// <param name="format"> The format. </param>
/// <param name="args"> The args. </param>
/// <exception cref="System.NotImplementedException"> This is currently not implemented. </exception>
public void LogWarning(string format, params object[] args)
{
// Do Nothing.
if (EqtTrace.IsWarningEnabled)
{
EqtTrace.Warning(this.PrependAdapterName(format, args));
}
}

/// <summary>
/// Log an information message in a given format.
/// </summary>
/// <param name="format"> The format. </param>
/// <param name="args"> The args. </param>
/// <exception cref="System.NotImplementedException"> This is currently not implemented. </exception>
public void LogInfo(string format, params object[] args)
{
// Do Nothing.
if (EqtTrace.IsInfoEnabled)
{
EqtTrace.Info(this.PrependAdapterName(format, args));
}
}

private string PrependAdapterName(string format, params object[] args)
{
return string.Format($"MSTest - {string.Format(format, args)}");
}
}

Expand Down

0 comments on commit 956f367

Please sign in to comment.