Beispiel #1
0
        private void ConsumeDeferredEnable(string eventSourceName, Action <DeferredEnable> action)
        {
            DeferredEnable previousEnable = null;

            for (var currentDeferredEnable = this.deferredEnables; currentDeferredEnable != null; currentDeferredEnable = currentDeferredEnable.Next)
            {
                if (string.Equals(currentDeferredEnable.EventSourceName, eventSourceName, StringComparison.Ordinal))
                {
                    // consume the deferred enable
                    action(currentDeferredEnable);

                    // remove the entry
                    if (previousEnable == null)
                    {
                        this.deferredEnables = currentDeferredEnable.Next;
                    }
                    else
                    {
                        previousEnable.Next = currentDeferredEnable.Next;
                    }

                    return;
                }

                previousEnable = currentDeferredEnable;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Enables events for the specified event source that has the specified verbosity level or lower, and matching keyword flags.
        /// </summary>
        /// <param name="eventSourceName">The name of the event source to enable events for.</param>
        /// <param name="level">The level of events to enable.</param>
        /// <param name="matchAnyKeyword">The keyword flags necessary to enable the events.</param>
        /// <param name="arguments">The arguments to be matched to enable the events.</param>
        /// <returns>
        ///   <see langword="false" /> if the request was deferred; otherwise, <see langword="true" />.
        /// </returns>
        /// <remarks>
        /// If the event source with the supplied name has already been created the request is processed immediately. Otherwise the request
        /// is deferred until the event source is created.
        /// </remarks>
        public bool EnableEvents(string eventSourceName, EventLevel level, EventKeywords matchAnyKeyword, IDictionary <string, string> arguments)
        {
            Guard.ArgumentNotNullOrEmpty(eventSourceName, "eventSourceName");

            lock (this.deferredEnablePadlock)
            {
                foreach (var eventSource in EventSource.GetSources())
                {
                    if (string.Equals(eventSource.Name, eventSourceName, StringComparison.Ordinal))
                    {
                        this.EnableEvents(eventSource, level, matchAnyKeyword, arguments);

                        return(true);
                    }
                }

                // remove any previous deferred enable for the same source name and add a new one
                this.ConsumeDeferredEnable(eventSourceName, _ => { });
                this.deferredEnables =
                    new DeferredEnable
                {
                    EventSourceName = eventSourceName,
                    Level           = level,
                    MatchAnyKeyword = matchAnyKeyword,
                    Arguments       = arguments != null ? new Dictionary <string, string>(arguments) : null,
                    Next            = this.deferredEnables
                };

                return(false);
            }
        }