I'm getting an Object Disposed Exception when I try to call TraceSource.TraceData with my VS2008 unit test project. I have included a very small code sample below which consistently repros the issue. I'm only seeing this after I run my first unit test - but I have a hunch it'll affect me once my website is up and running with lots of users.
It's like the underlying stream is being closed after the first unit test. Any help greatly from the 'overflow' gurus would be v much appreciated.
Steps:
1) Create a VS 2008 Unit Test project
2) Add a class with this code:
namespace TracingError
{
using System.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public class UnitTest1
{
public static TraceSource ts = new TraceSource("TraceTest");
[TestMethod]
public void A()
{
ts.TraceEvent(TraceEventType.Information, 1, "Hello from A");
}
[TestMethod]
public void B()
{
ts.TraceEvent(TraceEventType.Information, 1, "Hello from B");
}
}
}
3) Add an app.config with this code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<sources>
<source name="TraceTest" switchName="SourceSwitch" switchType="System.Diagnostics.SourceSwitch">
<listeners>
<add name="console" type="System.Diagnostics.ConsoleTraceListener" initializeData="false" />
<remove name="Default" />
</listeners>
</source>
</sources>
<switches>
<add name="SourceSwitch" value="Verbose" />
</switches>
<trace autoflush="true" indentsize="4"></trace>
</system.diagnostics>
</configuration>