コード例 #1
0
        public void UpdateSession(IEnumerable <EventSourceSettings> updatedEventSources)
        {
            Guard.ArgumentNotNull(updatedEventSources, "updatedEventSources");

            var eventSourceComparer = new EventSourceSettingsEqualityComparer(nameOnly: true);

            // updated sources
            foreach (var currentSource in this.eventSources.Intersect(updatedEventSources, eventSourceComparer).ToArray())
            {
                var updatedSource = updatedEventSources.Single(s => s.Name == currentSource.Name);
                if (updatedSource.Level != currentSource.Level ||
                    updatedSource.MatchAnyKeyword != currentSource.MatchAnyKeyword)
                {
                    TraceEventUtil.EnableProvider(this.session, updatedSource.EventSourceId, updatedSource.Level, updatedSource.MatchAnyKeyword, sendManifest: false);
                    currentSource.Level           = updatedSource.Level;
                    currentSource.MatchAnyKeyword = updatedSource.MatchAnyKeyword;
                }
            }

            // new sources
            foreach (var newSource in updatedEventSources.Except(this.eventSources, eventSourceComparer).ToArray())
            {
                TraceEventUtil.EnableProvider(this.session, newSource.EventSourceId, newSource.Level, newSource.MatchAnyKeyword, sendManifest: true);
                this.eventSources.Add(newSource);
            }

            // removed sources
            foreach (var removedSource in this.eventSources.Except(updatedEventSources, eventSourceComparer).ToArray())
            {
                this.session.DisableProvider(removedSource.EventSourceId);
                this.eventSources.Remove(removedSource);
            }
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        public void UpdateSession(IEnumerable <Configuration.EventSourceSettings> updatedEventSources)
        {
            Guard.ArgumentNotNull(updatedEventSources, "updatedEventSources");
            var updatedSources = updatedEventSources as Configuration.EventSourceSettings[] ?? updatedEventSources.ToArray();

            var eventSourceNameComparer = new EventSourceSettingsEqualityComparer(nameOnly: true);
            var eventSourceFullComparer = new EventSourceSettingsEqualityComparer(nameOnly: false);

            // updated sources
            foreach (var currentSource in this.eventSources.Intersect(updatedSources, eventSourceNameComparer).ToArray())
            {
                var updatedSource = updatedSources.Single(s => s.Name == currentSource.Name);
                if (!eventSourceFullComparer.Equals(currentSource, updatedSource))
                {
                    currentSource.CopyValuesFrom(updatedSource);
                    TraceEventUtil.EnableProvider(
                        this.session,
                        currentSource.EventSourceId,
                        currentSource.Level,
                        currentSource.MatchAnyKeyword,
                        currentSource.Arguments,
                        currentSource.ProcessNamesToFilter,
                        sendManifest: false);
                }
            }

            // new sources
            foreach (var newSource in updatedSources.Except(this.eventSources, eventSourceNameComparer).ToArray())
            {
                TraceEventUtil.EnableProvider(
                    this.session,
                    newSource.EventSourceId,
                    newSource.Level,
                    newSource.MatchAnyKeyword,
                    newSource.Arguments,
                    newSource.ProcessNamesToFilter,
                    sendManifest: true);
                this.eventSources.Add(newSource);
            }

            // removed sources
            foreach (var removedSource in this.eventSources.Except(updatedSources, eventSourceNameComparer).ToArray())
            {
                this.session.DisableProvider(removedSource.EventSourceId);
                this.eventSources.Remove(removedSource);
            }
        }