I'm trying to use Event Tracing for Windows (ETW) in my .NET application via the EventSource class that was included in .NET 4.5. I'm subclassing EventSource
as MyEventSource
and trying to implement an interface IMyEventSource
(for mocking purposes) as follows:
public interface IMyEventSource
{
void Test();
}
public class MyEventSource : EventSource, IMyEventSource
{
public static MyEventSource Log = new MyEventSource();
[Event(1)]
public void Test()
{
this.WriteEvent(1);
}
}
When I run PerfView and execute this code, I get an IndexOutOfRangeException
on the call to WriteEvent
. If I remove the interface by modifying the code...
public class MyEventSource : EventSource
{
public static MyEventSource Log = new MyEventSource();
[Event(1)]
public void Test()
{
this.WriteEvent(1);
}
}
...then everything works just fine.
Here is the code I used for testing in both cases:
static void Main(string[] args)
{
MyEventSource.Log.Test();
}
Why does my subclass of EventSource
break if it simply implements an interface?
Here is a related post.