private void Initialize() { this.session = TraceEventUtil.CreateSession(this.sessionName); // Hook up the ETWTraceEventSource to the specified session this.source = new ETWTraceEventSource(this.sessionName, TraceEventSourceType.Session); this.manifestCache = new TraceEventManifestsCache(this.source.Dynamic); // get any previously cached manifest this.manifestCache.Read(); // hook up to all incoming events and filter out manifests this.source.Dynamic.All += e => this.ProcessEvent(e); // listen to new manifests this.source.Dynamic.ManifestReceived += m => this.OnManifestReceived(m); // We collect all the manifests and save/terminate process when done this.source.UnhandledEvent += e => this.ProcessUnhandledEvent(e); foreach (var eventSource in this.eventSources) { // Bind the provider (EventSource/EventListener) with the session TraceEventUtil.EnableProvider(this.session, eventSource.EventSourceId, eventSource.Level, eventSource.MatchAnyKeyword); } // source.Process() is blocking so we need to launch it on a separate thread. this.workerTask = Task.Factory.StartNew(() => this.source.Process(), TaskCreationOptions.LongRunning). ContinueWith(t => this.HandleProcessTaskFault(t)); }