Skip to content

Commit 799ecfc

Browse files
authored
fix: Console logs are outputted twice when using TestAdapter (#2790)
* chore: fix issue that console logs are outputted twice when using testadapter * chore: fix code that are pointed out by code review
1 parent f8390f8 commit 799ecfc

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/BenchmarkDotNet.TestAdapter/BenchmarkExecutor.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using BenchmarkDotNet.Configs;
2+
using BenchmarkDotNet.Loggers;
23
using BenchmarkDotNet.Running;
34
using BenchmarkDotNet.TestAdapter.Remoting;
45
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
@@ -67,7 +68,10 @@ public void RunBenchmarks(string assemblyPath, TestExecutionRecorderWrapper reco
6768
.Select(b => new BenchmarkRunInfo(
6869
b.BenchmarksCases,
6970
b.Type,
70-
b.Config.AddEventProcessor(eventProcessor).AddLogger(logger).CreateImmutableConfig()))
71+
b.Config.AddEventProcessor(eventProcessor)
72+
.AddLogger(logger)
73+
.RemoveLoggersOfType<ConsoleLogger>() // Console logs are also outputted by VSTestLogger.
74+
.CreateImmutableConfig()))
7175
.ToArray();
7276

7377
// Run all the benchmarks, and ensure that any tests that don't have a result yet are sent.

src/BenchmarkDotNet/Configs/ManualConfig.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,12 @@ public static ManualConfig Union(IConfig globalConfig, IConfig localConfig)
327327
return manualConfig;
328328
}
329329

330+
internal ManualConfig RemoveLoggersOfType<T>()
331+
{
332+
loggers.RemoveAll(logger => logger is T);
333+
return this;
334+
}
335+
330336
internal void RemoveAllJobs() => jobs.Clear();
331337

332338
internal void RemoveAllDiagnosers() => diagnosers.Clear();

0 commit comments

Comments
 (0)