/// <summary> /// Observe In-Process EventSource events. It's no across ETW. /// </summary> public static IObservable <EventWrittenEventArgs> FromEventSource(string eventSourceName, EventLevel level = EventLevel.Verbose, EventKeywords matchAnyKeyword = EventKeywords.None, IDictionary <string, string> arguments = null) { if (eventSourceName == null) { throw new ArgumentNullException("eventSourceName"); } foreach (var item in EventSource.GetSources()) { if (item.Name.Equals(eventSourceName, StringComparison.Ordinal)) { return(FromEventSource(item, level)); } } var listener = new SystemEventSourceListener(); listener.RegisterDelay(new SystemArgs { EventSourceName = eventSourceName, Level = level, MatchAnyKeyword = matchAnyKeyword, Arguments = arguments }); return(listener); }
/// <summary> /// Observe In-Process EventSource events. It's no across ETW. /// </summary> public static IObservable <EventWrittenEventArgs> FromEventSource(EventSource eventSource, EventLevel level = EventLevel.Verbose, EventKeywords matchAnyKeyword = EventKeywords.None, IDictionary <string, string> arguments = null) { if (eventSource == null) { throw new ArgumentNullException("eventSource"); } var listener = new SystemEventSourceListener(); listener.EnableEvents(eventSource, level, matchAnyKeyword, arguments); return(listener.Finally(() => listener.DisableEvents(eventSource))); }