It turns out that the reason why events are missing is pretty subtle.
For the simplicity I didn't provide all my code, just part which I thought is important - the method where I'm calling EventSource.WriteEvent
.
It's interesting that if an EventSource-implementation class contains ANY other method where EventSource.WriteEvent
is being called with the same id then you won't see ANY events from this EventSource. It's unbelievable but it is.
So my class had one more method with WriteEvent call which I didn't use:
[EventSource(Name = "WebApi")]
public class WebApiEventSource : EventSource
{
public static readonly WebApiEventSource Log = new WebApiEventSource();
public void Event(string url, string message)
{
WriteEvent(1, url, message);
}
public void Event2(string url, string message)
{
WriteEvent(1, url, message);
}
}
After that I removed my additional method (Event2) I did see my events in PerfView log!
NOTE: And applying EventAttribute is totally optional indeed.
Another reason I found is that that method which calls WriteEvent
should not have arguments which are not strings.