0

I have a unit tests dll that is run using vstest.console.exe. Inside the unit tests I log some debugging information using a TraceSource. When I run the unit tests in Visual Studio, I can see the logs in the output windows, but when I run it by vstest.console.exe with /Logger:trx option, the output logs are not there.

I tried to replace the TraceSource with the static Trace and this actually worked and the logs show in trx file. Any Idea why the logs from the TraceSource do not show as opposed to showing when using Trace ?

My usage of the TraceSource is as follows:

TraceSource traceSource = new TraceSource("TraceSourceTraceLogger");
traceSource.Listeners.Clear();
traceSource.Listeners.Add(new DefaultTraceListener());
traceSource.Listeners.Add(new ConsoleTraceListener());
var sourceSwitch = new SourceSwitch("TraceSourceTraceLoggerSwitch") { Level = SourceLevels.All };
traceSource.Switch = sourceSwitch;
traceSource.TraceInformation("This is a debug message");

And the App.config has:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.diagnostics>
    <trace autoflush="true" />
  </system.diagnostics>
</configuration>

Thanks in advance.

askso
  • 85
  • 8

1 Answers1

0

The problem turned out that the TraceSource I was using was a static instance inside a static class.

A static TraceSource in a non-static class works though.

askso
  • 85
  • 8