I have a DLL that's a bit on the complicated side that I'm writing tests against. Most of the classes under test have their own TraceSource
object that are used to output tracing information.
namespace MyDll
{
public class Class1
{
static TraceSource tracing = new TraceSource(nameof(Class1));
//Instance members and functions...
}
public class Class2
{
static TraceSource tracing = new TraceSource(nameof(Class2));
//Instance members and functions...
}
public class Class3
{
static TraceSource tracing = new TraceSource(nameof(Class3));
//Instance members and functions...
}
}
Inside of the MyDll
project is an App.config
file that adds a common ConsoleTraceListener
to all of the TraceSource
, like so:
<configuration>
<system.diagnostics>
<sources>
<source name="Class1"
switchName="sourceSwitch"
switchType="System.Diagnostics.SourceSwitch">
<listeners>
<add name="console"/>
</listeners>
</source>
<source name="Class2"
switchName="sourceSwitch"
switchType="System.Diagnostics.SourceSwitch">
<listeners>
<add name="console"/>
</listeners>
</source>
<source name="Class3"
switchName="sourceSwitch"
switchType="System.Diagnostics.SourceSwitch">
<listeners>
<add name="console"/>
</listeners>
</source>
</sources>
<switches>
<add name="sourceSwitch" value="Verbose"/>
</switches>
<sharedListeners>
<add name="console"
type="System.Diagnostics.ConsoleTraceListener">
<filter type="System.Diagnostics.EventTypeFilter"
initializeData="Verbose"/>
</add>
</sharedListeners>
</system.diagnostics>
</configuration>
App.config
is configured to always copy to the output directory. I'm not sure if that's relevant.
Here's the problem: If I run 1 test, I get all of the tracing information in the Output from the test. However, if I run all of the tests, only the first test run will have the tracing from the code under test. All of the other tests do not have any output.
How can I get MSTest to output all tracing information from all TraceSource
for all tests?