Пример #1
0
 public void WaitForEnable(EventSource logger)
 {
     if (!SpinWait.SpinUntil(() => logger.IsEnabled(), TimeSpan.FromSeconds(10)))
     {
         throw new InvalidOperationException("EventSource not enabled after 5 seconds");
     }
 }
Пример #2
0
 protected override void OnEventSourceCreated(System.Diagnostics.Tracing.EventSource eventSource)
 {
     if (eventSource.Name == "Microsoft-Extensions-Logging")
     {
         _loggingEventSource = eventSource;
     }
 }
Пример #3
0
 internal void EnableTimer(EventSource eventSource, int pollingTime)
 {
     FilteringOptions options = new FilteringOptions();
     options.Args = new Dictionary<string, string>();
     options.Args.Add("EventCounterIntervalSec", pollingTime.ToString());
     EventSourceCommand(eventSource.Name, EventCommand.Enable, options);
 }
Пример #4
0
 private void EnableSourceIfMatch(EventSource source)
 {
     if (_targetSourceName.ContainsKey(source.Name))
     {
         EnableEvents(source, _level);
     }
 }
Пример #5
0
        private void Test_BadTypes_Manifest(EventSource source)
        {
            try
            {
                var listener = new EventListenerListener();

                var events = new List<Event>();
                Debug.WriteLine("Adding delegate to onevent");
                listener.OnEvent = delegate (Event data) { events.Add(data); };

                listener.EventSourceCommand(source.Name, EventCommand.Enable);

                listener.Dispose();

                // Confirm that we get exactly one event from this whole process, that has the error message we expect.  
                Assert.Equal(events.Count, 1);
                Event _event = events[0];
                Assert.Equal("EventSourceMessage", _event.EventName);
                string message = _event.PayloadString(0, "message");
                // expected message: "ERROR: Exception in Command Processing for EventSource BadEventSource_Bad_Type_ByteArray: Unsupported type Byte[] in event source. "
                Assert.True(Regex.IsMatch(message, "Unsupported type"));
            }
            finally
            {
                source.Dispose();
            }
        }
        static ReadOnlyDictionary <int, EventSchemaPortion> GetEventSchemaPortions(System.Diagnostics.Tracing.EventSource source)
        {
            return(cache.GetOrAdd(source, s => // no needs lock
            {
                var manifest = System.Diagnostics.Tracing.EventSource.GenerateManifest(s.GetType(), null);

                var xElem = XElement.Parse(manifest);
                var ns = xElem.Name.Namespace;

                // { tid : {[payloadNames]}}
                var tidRef = xElem.Descendants(ns + "template")
                             .ToDictionary(x => x.Attribute("tid").Value, x => new ReadOnlyCollection <string>(
                                               x.Elements(ns + "data")
                                               .Select(y => y.Attribute("name").Value)
                                               .ToArray()));

                var dict = xElem.Descendants(ns + "event")
                           .ToDictionary(x => int.Parse(x.Attribute("value").Value), x => new EventSchemaPortion(
                                             x.Attribute("template")?.Value != null ? tidRef[x.Attribute("template").Value] : new string[0].ToList().AsReadOnly(),
                                             x.Attribute("keywords")?.Value ?? "",
                                             x.Attribute("task")?.Value ?? x.Attribute("symbol").Value));

                return new ReadOnlyDictionary <int, EventSchemaPortion>(dict);
            }));
        }
Пример #7
0
 private void EnableSourceIfMatch(EventSource source)
 {
     if (source.Name.Equals(_targetSourceName) || 
         source.Guid.Equals(_targetSourceGuid))
     {
         EnableEvents(source, _level);
     }
 }
Пример #8
0
 protected override void OnEventSourceCreated(System.Diagnostics.Tracing.EventSource eventSource)
 {
     if (eventSource.Name == "Microsoft-Extensions-Logging")
     {
         DisableEvents(eventSource);
         EnableEvents(eventSource, EventLevel.Verbose, _keywords);
     }
 }
 protected override void OnEventSourceCreated(EventSource eventSource)
 {
     // Check for null because this method is called by the base class constror before we can initialize it
     Action<EventSource> callback = this.OnOnEventSourceCreated;
     if (callback != null)
     {
         callback(eventSource);
     }
 }
Пример #10
0
        /// <summary>Called for all existing event sources when the event listener is created and when a new event
        /// source is attached to the listener. Enables log sources to the appropriate event level.</summary>
        /// <param name="eventSource">The event source.</param>
        protected override void OnEventSourceCreated(EventSource eventSource)
        {
            var log = eventSource as Log;

            if (log != null)
            {
                this.EnableEvents(log, this.eventLevel);
            }
        }
        public EventProviderSubscription(EventSource source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            this.Source = source;
        }
        protected override void OnEventSourceCreated(EventSource eventSource)
        {
            base.OnEventSourceCreated(eventSource);

            if (eventSource.Name.Equals(Constants.LogSourceName))
            {
                this.EnableEvents(eventSource, EventLevel.Verbose);
            }
        }
        /// <summary>
        /// Enables HTTP event source when EventSource is created. Called for all existing 
        /// event sources when the event listener is created and when a new event source is attached to the listener.
        /// </summary>
        protected override void OnEventSourceCreated(EventSource eventSource)
        {
            if (eventSource != null && eventSource.Name == FrameworkEventSourceName)
            {
                this.EnableEvents(eventSource, EventLevel.Informational, (EventKeywords)4);
                DependencyCollectorEventSource.Log.RemoteDependencyModuleVerbose("HttpEventListener initialized for event source:" + FrameworkEventSourceName);
            }

            base.OnEventSourceCreated(eventSource);
        }
            protected override void OnEventSourceCreated(EventSource eventSource)
            {
                if (_providers == null)
                {
                    _eventSourcesToEnable.Add(eventSource);
                }

                if (IsIntendedEventSource(eventSource))
                {
                    this.EnableEvents(eventSource, EventLevel.LogAlways);
                }
            }
Пример #15
0
            protected override void OnEventSourceCreated(System.Diagnostics.Tracing.EventSource eventSource)
            {
                if (eventSource.Name == "Microsoft-Extensions-Logging")
                {
                    _loggingEventSource = eventSource;
                }

                if (_enableWhenCreated != null)
                {
                    EnableEvents(_loggingEventSource, _enableWhenCreated.Level, _enableWhenCreated.Keywords, GetArguments(_enableWhenCreated));
                    _enableWhenCreated = null;
                }
            }
        /// <summary>
        /// Gets the <see cref="EventSchema"/> for the specified eventId and eventSource.
        /// </summary>
        /// <param name="eventId">The ID of the event.</param>
        /// <param name="eventSource">The event source.</param>
        /// <returns>The EventSchema.</returns>
        public EventSchema GetSchema(int eventId, EventSource eventSource)
        {
            Guard.ArgumentNotNull(eventSource, "eventSource");

            IReadOnlyDictionary<int, EventSchema> events;

            if (!this.schemas.TryGetValue(eventSource.Guid, out events))
            {
                events = new ReadOnlyDictionary<int, EventSchema>(this.schemaReader.GetSchema(eventSource));
                this.schemas[eventSource.Guid] = events;
            }

            return events[eventId];
        }
Пример #17
0
 public void Test_EventSource_Traits_Dynamic()
 {
     TestUtilities.CheckNoEventSourcesRunning("Start");
     using (var mySource = new EventSource("DynamicEventSourceWithTraits", EventSourceSettings.Default,
         "MyTrait", "MyTraitValue",
         "ETW_GROUP", "{4f50731a-89cf-4782-b3e0-dce8c90476ba}"))
     {
         // By default we are self-describing.  
         Assert.Equal(mySource.Settings, EventSourceSettings.EtwSelfDescribingEventFormat);
         Assert.Equal(mySource.GetTrait("MyTrait"), "MyTraitValue");
         Assert.Equal(mySource.GetTrait("ETW_GROUP"), "{4f50731a-89cf-4782-b3e0-dce8c90476ba}");
     }
     TestUtilities.CheckNoEventSourcesRunning("Stop");
 }
Пример #18
0
        protected override void OnEventSourceCreated(EventSource eventSource)
        {
            List<EventSource> tmp = _tmpEventSourceList;
            if (tmp != null)
            {
                lock (tmp)
                {
                    if (_tmpEventSourceList != null)
                    {
                        _tmpEventSourceList.Add(eventSource);
                        return;
                    }
                }
            }

            EnableSourceIfMatch(eventSource);
        }
Пример #19
0
        public static void With2Listeners(EventSource logger, Action<ObservableEventListener, ObservableEventListener> scenario)
        {
            using (var listener1 = new ObservableEventListener())
            using (var listener2 = new ObservableEventListener())
            {
                try
                {
                    scenario(listener1, listener2);
                }
                finally
                {
                    try
                    { listener1.DisableEvents(logger); }
                    catch
                    { }

                    try
                    { listener2.DisableEvents(logger); }
                    catch
                    { }
                }
            }
        }
Пример #20
0
 public void EnableEvents(EventSource eventSource, EventLevel level, EventKeywords matchAnyKeyword, IDictionary <string, string> arguments)
 {
 }
Пример #21
0
 /// <summary>
 /// This method is called whenever a new eventSource is 'attached' to the dispatcher.
 /// This can happen for all existing EventSources when the EventListener is created
 /// as well as for any EventSources that come into existance after the EventListener
 /// has been created.
 /// 
 /// These 'catch up' events are called during the construction of the EventListener.
 /// Subclasses need to be prepared for that.
 /// 
 /// In a multi-threaded environment, it is possible that 'OnEventWritten' callbacks
 /// for a paritcular eventSource to occur BEFORE the OnEventSourceCreated is issued.
 /// </summary>
 /// <param name="eventSource"></param>
 internal protected virtual void OnEventSourceCreated(EventSource eventSource) { }
Пример #22
0
        /// <summary>
        /// Send a command to a particular EventSource identified by 'eventSource'
        /// 
        /// Calling this routine simply forwards the command to the EventSource.OnEventCommand
        /// callback.  What the EventSource does with the command and its arguments are from that point
        /// EventSource-specific.  
        /// 
        /// The eventSource is passed the EventListener that issued the command along with the command and
        /// arguments.  The contract is that to the extent possible the eventSource should not affect other
        /// EventListeners (eg filtering events), however sometimes this simply is not possible (if the
        /// command was to provoke a GC, or a System flush etc).   
        /// </summary>
        public static void SendCommand(EventSource eventSource, EventCommand command, IDictionary<string, string> commandArguments)
        {
            if (eventSource == null)
                throw new ArgumentNullException(nameof(eventSource));

            // User-defined EventCommands should not conflict with the reserved commands.
            if ((int)command <= (int)EventCommand.Update && (int)command != (int)EventCommand.SendManifest)
                throw new ArgumentException(SR.ArgumentOutOfRange_NeedPosNum, nameof(command));

            eventSource.SendCommand(null, command, true, EventLevel.LogAlways, EventKeywords.None, commandArguments);
        }
Пример #23
0
        // We don't expose a Dispose(bool), because the contract is that you don't have any non-syncronous
        // 'cleanup' associated with this object

        /// Enable all events from the curEventSource identified by 'eventSource' to the current dispatcher that have a
        /// verbosity level of 'level' or lower.
        ///   
        /// This call can have the effect of REDUCING the number of events sent to the dispatcher if 'level'
        /// indicates a less verbose level than was previously enabled.
        /// 
        /// This call never has an effect on other EventListeners.
        ///
        /// Returns 'true' if any curEventSource could be found that matches 'eventSourceGuid'
        /// </summary>
        public void EnableEvents(EventSource eventSource, EventLevel level)
        {
            EnableEvents(eventSource, level, EventKeywords.None);
        }
Пример #24
0
        /// <summary>
        /// Enable all events from the eventSource identified by 'eventSource' to the current dispatcher that have a
        /// verbosity level of 'level' or lower and have a event keyword matching any of the bits in
        /// 'machAnyKeyword' as well as any (curEventSource specific) effect passing addingional 'key-value' arguments
        /// 'arguments' might have.  
        /// 
        /// This call can have the effect of REDUCING the number of events sent to the dispatcher if 'level'
        /// indicates a less verbose level than was previously enabled or if 'machAnyKeyword' has fewer
        /// keywords set than where previously set.
        /// 
        /// This call never has an effect on other EventListeners.
        /// </summary>       
        public void EnableEvents(EventSource eventSource, EventLevel level, EventKeywords matchAnyKeyword, IDictionary<string, string> arguments)
        {
            if (eventSource == null)
            {
                throw new ArgumentNullException(nameof(eventSource));
            }

            Contract.EndContractBlock();

            eventSource.SendCommand(this, EventCommand.Update, true, level, matchAnyKeyword, arguments);
        }
Пример #25
0
        protected unsafe void WriteEventCore(int eventId, int eventDataCount, EventSource.EventData* data)
        {
            if (m_eventData != null)
            {
                if (m_eventData[eventId].EnabledForETW)
                {
                    EventProvider.EventData* dataDescrs = stackalloc EventProvider.EventData[eventDataCount];
                    if (eventDataCount <= 0)
                    {
                        // EventWrite expects NULL if dataDescrs is zero.
                        // You cannot pass a ptr to an empty array.
                        dataDescrs = (EventProvider.EventData*)IntPtr.Zero;
                    }

                    for (int i = 0; i < eventDataCount; i++)
                    {
                        dataDescrs[i].Size = (uint)data[i].Size;
                        dataDescrs[i].Ptr = (ulong)(data[i].DataPointer.ToInt64());
                        dataDescrs[i].Reserved = 0;
                    }

                    if (!m_provider.WriteEvent(ref m_eventData[eventId].Descriptor, eventDataCount, (IntPtr)dataDescrs) && m_throwOnEventWriteErrors)
                        throw new EventSourceException();
                }

                if (m_Dispatchers != null && m_eventData[eventId].EnabledForAnyListener)
                {
                    object[] args = new object[eventDataCount];

                    for (int i = 0; i < eventDataCount; i++)
                    {
                        args[i] = DecodeObject(eventId, i, data[i].Size, data[i].DataPointer);
                    }

                    WriteToAllListeners(eventId, args);
                }
            }
        }
Пример #26
0
 internal protected  override void OnEventSourceCreated(EventSource eventSource)
 {
     string eventSourceFilter = eventSourceNameFilter.Value;
     if (String.IsNullOrEmpty(eventSourceFilter) || (eventSource.Name.IndexOf(eventSourceFilter, StringComparison.OrdinalIgnoreCase) >= 0))
     {   
         EnableEvents(eventSource, EventLevel.LogAlways, EventKeywords.All, null);
     }
 }
Пример #27
0
 internal CounterGroup(EventSource eventSource)
 {
     _eventSource = eventSource;
     _counters    = new List <DiagnosticCounter>();
     RegisterCommandCallback();
 }
Пример #28
0
 public void EnableEvents(EventSource eventSource, EventLevel level)
 {
 }
Пример #29
0
 internal EventWrittenEventArgs(EventSource eventSource)
 {
     this.m_eventSource = eventSource;
 }
Пример #30
0
 protected internal virtual void OnEventSourceCreated(EventSource eventSource)
 {
 }
Пример #31
0
 public void DisableEvents(EventSource eventSource)
 {
 }
Пример #32
0
 internal protected  override void OnEventSourceCreated(EventSource eventSource)
 {
     EnableEvents(eventSource, EventLevel.LogAlways, EventKeywords.All, null);
 }
 protected override void OnEventSourceCreated(EventSource eventSource)
 {
     if (eventSource.Name == "Microsoft-Diagnostics-DiagnosticSource")
         _diagnosticSourceEventSource = eventSource;
 }
 // Token: 0x0600350E RID: 13582 RVA: 0x000CDDB2 File Offset: 0x000CBFB2
 public void Write <T>(EventSource source, string eventName, EventSourceOptions options, T data)
 {
     this.Write <T>(source, eventName, ref options, ref data);
 }
Пример #35
0
 // Token: 0x060033ED RID: 13293 RVA: 0x000C985C File Offset: 0x000C7A5C
 internal EventCommandEventArgs(EventCommand command, IDictionary <string, string> arguments, EventSource eventSource, EventListener listener, int perEventSourceSessionId, int etwSessionId, bool enable, EventLevel level, EventKeywords matchAnyKeyword)
 {
     this.Command                 = command;
     this.Arguments               = arguments;
     this.eventSource             = eventSource;
     this.listener                = listener;
     this.perEventSourceSessionId = perEventSourceSessionId;
     this.etwSessionId            = etwSessionId;
     this.enable          = enable;
     this.level           = level;
     this.matchAnyKeyword = matchAnyKeyword;
 }
Пример #36
0
 /// <summary>
 /// All Counters live as long as the EventSource that they are attached to unless they are
 /// explicitly Disposed.
 /// </summary>
 /// <param name="Name">The name.</param>
 /// <param name="EventSource">The event source.</param>
 internal DiagnosticCounter(string Name, EventSource EventSource)
 {
     this.Name        = Name ?? throw new ArgumentNullException(nameof(Name));
     this.EventSource = EventSource ?? throw new ArgumentNullException(nameof(EventSource));
 }
Пример #37
0
 internal EventCommandEventArgs(EventCommand command, IDictionary<string, string> arguments, EventSource eventSource, EventDispatcher dispatcher)
 {
     this.Command = command;
     this.Arguments = arguments;
     this.eventSource = eventSource;
     this.dispatcher = dispatcher;
 }
Пример #38
0
 /// <summary>
 /// Enable all events from the eventSource identified by 'eventSourceGuid' to the current dispatcher that have a
 /// verbosity level of 'level' or lower and have a event keyword matching any of the bits in
 /// 'machAnyKeyword'.
 /// 
 /// This call can have the effect of REDUCING the number of events sent to the dispatcher if 'level'
 /// indicates a less verbose level than was previously enabled or if 'machAnyKeyword' has fewer
 /// keywords set than where previously set.
 /// 
 /// If eventSourceGuid is Guid.Empty, then the affects all eventSources in the appdomain
 /// 
 /// If eventSourceGuid is not Guid.Empty, this call has no effect on any other eventSources in the appdomain.
 /// 
 /// This call never has an effect on other EventListeners.
 /// 
 /// Returns 'true' if any eventSource could be found that matches 'eventSourceGuid'        
 /// </summary>
 public void EnableEvents(EventSource eventSource, EventLevel level, EventKeywords matchAnyKeyword)
 {
     EnableEvents(eventSource, level, matchAnyKeyword, null);
 }
Пример #39
0
 /// <summary>
 /// Initializes a new instance of the <see cref="IncrementingEventCounter"/> class.
 /// IncrementingEventCounter live as long as the EventSource that they are attached to unless they are
 /// explicitly Disposed.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="eventSource">The event source.</param>
 public IncrementingEventCounter(string name, EventSource eventSource) : base(name, eventSource)
 {
     Publish();
 }
Пример #40
0
        /// <summary>
        /// Disables all events coming from eventSource identified by 'eventSource'.  
        /// 
        /// If eventSourceGuid is Guid.Empty, then the affects all eventSources in the appdomain
        /// 
        /// This call never has an effect on other EventListeners.      
        /// </summary>
        public void DisableEvents(EventSource eventSource)
        {
            if (eventSource == null)
            {
                throw new ArgumentNullException(nameof(eventSource));
            }

            Contract.EndContractBlock();

            eventSource.SendCommand(this, EventCommand.Update, false, EventLevel.LogAlways, EventKeywords.None, null);
        }
 public EventCounter(string name, System.Diagnostics.Tracing.EventSource eventSource)
 {
 }
Пример #42
0
 /// <summary>
 /// EventSourceIndex is small non-negative integer (suitable for indexing in an array)
 /// identifying EventSource. It is unique per-appdomain. Some EventListeners might find
 /// it useful to store addditional information about each eventSource connected to it,
 /// and EventSourceIndex allows this extra infomation to be efficiently stored in a
 /// (growable) array (eg List(T)).
 /// </summary>
 static protected int EventSourceIndex(EventSource eventSource) { return eventSource.m_id; }
Пример #43
0
 public static int EventSourceIndex(EventSource eventSource)
 {
     return(0);
 }
Пример #44
0
        /// <summary>
        /// This routine adds newEventSource to the global list of eventSources, it also assigns the
        /// ID to the eventSource (which is simply the oridinal in the global list).
        /// 
        /// EventSources currently do not pro-actively remove themselves from this list. Instead
        /// when eventSources's are GCed, the weak handle in this list naturally gets nulled, and
        /// we will reuse the slot. Today this list never shrinks (but we do reuse entries
        /// that are in the list). This seems OK since the expectation is that EventSources
        /// tend to live for the lifetime of the appdomain anyway (they tend to be used in
        /// global variables).
        /// </summary>
        /// <param name="newEventSource"></param>
        internal static void AddEventSource(EventSource newEventSource)
        {
            lock (EventListenersLock)
            {
                if (s_EventSources == null)
                    s_EventSources = new List<WeakReference>(2);

                // Periodically search the list for existing entries to reuse, this avoids
                // unbounded memory use if we keep recycling eventSources (an unlikely thing). 
                int newIndex = -1;
                if (s_EventSources.Count % 64 == 63)   // on every block of 64, fill up the block before continuing
                {
                    int i = s_EventSources.Count;      // Work from the top down. 
                    while (0 < i)
                    {
                        --i;
                        WeakReference weakRef = s_EventSources[i];
                        if (!weakRef.IsAlive)
                        {
                            newIndex = i;
                            weakRef.Target = newEventSource;
                            break;
                        }
                    }
                }
                if (newIndex < 0)
                {
                    newIndex = s_EventSources.Count;
                    s_EventSources.Add(new WeakReference(newEventSource));
                }
                newEventSource.m_id = newIndex;

                // Add every existing dispatcher to the new EventSource
                for (EventListener listener = s_Listeners; listener != null; listener = listener.m_Next)
                    newEventSource.AddListener(listener);

                Validate();
            }
        }
Пример #45
0
 public void EnableEvents(EventSource eventSource, EventLevel level, EventKeywords matchAnyKeyword)
 {
 }
Пример #46
0
 internal EventWrittenEventArgs(EventSource eventSource)
 {
     m_eventSource = eventSource;
 }
Пример #47
0
 public static void SendCommand(EventSource eventSource, EventCommand command, IDictionary <string, string> commandArguments)
 {
     throw new NotImplementedException();
 }
Пример #48
0
 public OverideEventProvider(EventSource eventSource)
 {
     this.m_eventSource = eventSource;
 }
Пример #49
0
 internal protected override void OnEventSourceCreated(EventSource eventSource)
 {
     EnableEvents(eventSource, EventLevel.LogAlways, EventKeywords.All, null);
 }
Пример #50
0
 protected override void OnEventSourceCreated(EventSource eventSource)
 {
     base.OnEventSourceCreated(eventSource);
     EnableEvents(eventSource, EventLevel.LogAlways, EventKeywords.All);
 }
Пример #51
0
        unsafe void EtwEnableCallBack(
            [In] ref System.Guid sourceId,
            [In] int controlCode,
            [In] byte setLevel,
            [In] long anyKeyword,
            [In] long allKeyword,
            [In] UnsafeNativeMethods.ManifestEtw.EVENT_FILTER_DESCRIPTOR *filterData,
            [In] void *callbackContext
            )
        {
            ControllerCommand            command = ControllerCommand.Update;
            IDictionary <string, string> args    = null;

            byte[] data;
            int    keyIndex;
            bool   skipFinalOnControllerCommand = false;

            EventSource.OutputDebugString(string.Format("EtwEnableCallBack(ctrl {0}, lvl {1}, any {2:x}, all {3:x})",
                                                        controlCode, setLevel, anyKeyword, allKeyword));
            if (controlCode == UnsafeNativeMethods.ManifestEtw.EVENT_CONTROL_CODE_ENABLE_PROVIDER)
            {
                m_enabled        = true;
                m_level          = setLevel;
                m_anyKeywordMask = anyKeyword;
                m_allKeywordMask = allKeyword;

                List <Tuple <SessionInfo, bool> > sessionsChanged = GetSessions();
                foreach (var session in sessionsChanged)
                {
                    int  sessionChanged = session.Item1.sessionIdBit;
                    int  etwSessionId   = session.Item1.etwSessionId;
                    bool bEnabling      = session.Item2;

                    EventSource.OutputDebugString(string.Format(CultureInfo.InvariantCulture, "EtwEnableCallBack: session changed {0}:{1}:{2}",
                                                                sessionChanged, etwSessionId, bEnabling));

                    skipFinalOnControllerCommand = true;
                    args = null;                                // reinitialize args for every session...

                    // if we get more than one session changed we have no way
                    // of knowing which one "filterData" belongs to
                    if (sessionsChanged.Count > 1)
                    {
                        filterData = null;
                    }

                    // read filter data only when a session is being *added*
                    if (bEnabling &&
                        GetDataFromController(etwSessionId, filterData, out command, out data, out keyIndex))
                    {
                        args = new Dictionary <string, string>(4);
                        while (keyIndex < data.Length)
                        {
                            int keyEnd   = FindNull(data, keyIndex);
                            int valueIdx = keyEnd + 1;
                            int valueEnd = FindNull(data, valueIdx);
                            if (valueEnd < data.Length)
                            {
                                string key   = System.Text.Encoding.UTF8.GetString(data, keyIndex, keyEnd - keyIndex);
                                string value = System.Text.Encoding.UTF8.GetString(data, valueIdx, valueEnd - valueIdx);
                                args[key] = value;
                            }
                            keyIndex = valueEnd + 1;
                        }
                    }

                    // execute OnControllerCommand once for every session that has changed.
                    try
                    {
                        OnControllerCommand(command, args, (bEnabling ? sessionChanged : -sessionChanged), etwSessionId);
                    }
                    catch (Exception)
                    {
                        // We want to ignore any failures that happen as a result of turning on this provider as to
                        // not crash the app.
                    }
                }
            }
            else if (controlCode == UnsafeNativeMethods.ManifestEtw.EVENT_CONTROL_CODE_DISABLE_PROVIDER)
            {
                m_enabled        = false;
                m_level          = 0;
                m_anyKeywordMask = 0;
                m_allKeywordMask = 0;
                m_liveSessions   = null;
            }
            else if (controlCode == UnsafeNativeMethods.ManifestEtw.EVENT_CONTROL_CODE_CAPTURE_STATE)
            {
                command = ControllerCommand.SendManifest;
            }
            else
            {
                return;     // per spec you ignore commands you don't recognise.
            }
            try
            {
                if (!skipFinalOnControllerCommand)
                {
                    OnControllerCommand(command, args, 0, 0);
                }
            }
            catch (Exception)
            {
                // We want to ignore any failures that happen as a result of turning on this provider as to
                // not crash the app.
            }
        }