jonwagner / EventSourceProxy

EventSourceProxy (ESP) is the easiest way to add scalable Event Tracing for Windows (ETW) logging to your .NET program
Other
97 stars 20 forks source link

do not return disposed event sources #48

Closed oocx closed 3 years ago

oocx commented 8 years ago

EventSourceImplementer caches the event sources it creates and returns cached event sources if it already has an instance of the requested event source type.

However, event sources are disposable. Once an event source instance was disposed, EventSourceImplementer still returns the disposed event source. On my machine, this causes the unit test "EventDataTypeTests.BuiltInTypesCanBeLogged" to fail.

A quick but dirty fix would be to use reflection to access the EventSource.IsDisposed property and create a new EventSource instance if the old instance is disposed.

A more complicated alternative solution could be to override Dispose in the generated EventSource proxy and call EventSourceImplementer to remove the instance from the cache.

I implemented the simple, reflection based solution in this pull request.