public void TestBasicOperations_IsSupported_False()
        {
            RemoteInvokeOptions options = new RemoteInvokeOptions();

            options.RuntimeConfigurationOptions.Add("System.Diagnostics.Tracing.EventSource.IsSupported", false);

            RemoteExecutor.Invoke(() =>
            {
                using (var log = new EventSourceTest())
                {
                    using (var listener = new LoudListener(log))
                    {
                        IEnumerable <EventSource> sources = EventSource.GetSources();
                        Assert.Empty(sources);

                        Assert.Null(EventSource.GenerateManifest(typeof(SimpleEventSource), string.Empty, EventManifestOptions.OnlyIfNeededForRegistration));
                        Assert.Null(EventSource.GenerateManifest(typeof(EventSourceTest), string.Empty, EventManifestOptions.AllCultures));

                        log.Event0();
                        Assert.Null(LoudListener.LastEvent);

                        EventSource.SendCommand(log, EventCommand.Enable, commandArguments: null);
                        Assert.False(log.IsEnabled());
                    }
                }
            }, options).Dispose();
        }
 private void InitializeEventSources()
 {
     foreach (EventSource source in EventSource.GetSources())
     {
         EnableEvents(source, EventLevel.LogAlways);
     }
 }
Example #3
0
 public void Dispose()
 {
     foreach (var source in EventSource.GetSources())
     {
         source.Dispose();
     }
 }
Example #4
0
 public PKPerformanceEventListener()
 {
     foreach (var s in EventSource.GetSources())
     {
         EnableEvents(s, EventLevel.Informational);
     }
 }
 private void GetNewSources()
 {
     foreach (var eventSource in EventSource.GetSources())
     {
         OnEventSourceCreated(eventSource);
     }
 }
Example #6
0
        public override void EventSourceCommand(string eventSourceName, EventCommand command, FilteringOptions options = null)
        {
            EventTestHarness.LogWriteLine("Sending command {0} to EventSource {1} Options {2}", eventSourceName, command, options);

            if (options == null)
            {
                options = new FilteringOptions();
            }

            foreach (EventSource source in EventSource.GetSources())
            {
                if (source.Name == eventSourceName)
                {
                    DoCommand(source, command, options);
                    return;
                }
            }

            _onEventSourceCreated += delegate(EventSource sourceBeingCreated)
            {
                if (eventSourceName != null && eventSourceName == sourceBeingCreated.Name)
                {
                    DoCommand(sourceBeingCreated, command, options);
                    eventSourceName = null;         // so we only do it once.
                }
            };
        }
Example #7
0
        /// <summary>
        /// Confirms that there are no EventSources running.
        /// </summary>
        /// <param name="message">Will be printed as part of the Assert</param>
        public static void CheckNoEventSourcesRunning(string message = "")
        {
            var eventSources = EventSource.GetSources();

            string eventSourceNames = "";

            foreach (var eventSource in EventSource.GetSources())
            {
                // Exempt sources built in to the framework that might be used by types involved in the tests
                if (eventSource.Name != "System.Threading.Tasks.TplEventSource" &&
                    eventSource.Name != "System.Diagnostics.Eventing.FrameworkEventSource" &&
                    eventSource.Name != "System.Buffers.ArrayPoolEventSource" &&
                    eventSource.Name != "System.Threading.SynchronizationEventSource" &&
                    eventSource.Name != "System.Runtime.InteropServices.InteropEventProvider" &&
                    eventSource.Name != "System.Reflection.Runtime.Tracing" &&
                    eventSource.Name != "Microsoft-Windows-DotNETRuntime"
                    )
                {
                    eventSourceNames += eventSource.Name + " ";
                }
            }

            Debug.WriteLine(message);
            Assert.Equal("", eventSourceNames);
        }
Example #8
0
        static void Main(string[] args)
        {
            //EventSource eventS = new EventSource();
            TraceSource trace = new TraceSource("Test");

            var listener = new ConsoleEventListener();

            //listener.EnableEvents(TestSource.Log, EventLevel.Verbose);
            foreach (var item in EventSource.GetSources())
            {
                listener.EnableEvents(item, EventLevel.LogAlways);
            }
            //listener.EnableEvents();

            Trace.TraceError("super");
            Trace.TraceInformation("super");
            Trace.TraceWarning("super");
            Trace.WriteLine("super");
            //Trace.Fail("super");

            trace.TraceEvent(TraceEventType.Verbose, 1, "test traceSource {0}", "!?");
            TestSource.Log.LogSuper("cool");


            Console.ReadLine();
        }
Example #9
0
        /// <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);
        }
Example #10
0
        static Function1()
        {
            var netEventSource = EventSource.GetSources().FirstOrDefault(es => es.Name == "Microsoft-System-Net-Http");

            if (netEventSource != null)
            {
                var myEventListener = new MyEventListener();

                myEventListener.EnableEvents(netEventSource, EventLevel.LogAlways);
            }

            string searchServiceName = Environment.GetEnvironmentVariable("SearchServiceName");
            string adminApiKey       = Environment.GetEnvironmentVariable("SearchServiceAdminApiKey");
            var    handler           = new KeepAliveAvailableHttpClientHandler();


            handler.ServerCertificateCustomValidationCallback = (sender, certificate, chain, sslPolicyErrors) =>
            {
                return(true);
            };
            var delegatingHanlder = new DelegatingHandlerImpl(handler);
            var hanlders          = new DelegatingHandler[]
            {
                delegatingHanlder
            };


            indexClient = new SearchIndexClient(searchServiceName, "azuresql-index", new SearchCredentials(adminApiKey), handler, hanlders);
        }
Example #11
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);
            }
        }
Example #12
0
        public override void EventSourceCommand(string eventSourceName, EventCommand command, FilteringOptions options = null)
        {
            if (options == null)
            {
                options = new FilteringOptions();
            }

            foreach (EventSource source in EventSource.GetSources())
            {
                if (source.Name == eventSourceName)
                {
                    DoCommand(source, command, options);
                    return;
                }
            }

            _onEventSourceCreated += delegate(EventSource sourceBeingCreated)
            {
                if (eventSourceName != null && eventSourceName == sourceBeingCreated.Name)
                {
                    DoCommand(sourceBeingCreated, command, options);
                    eventSourceName = null;         // so we only do it once.
                }
            };
        }
        public string[] Get()
        {
            var sources = EventSource.GetSources()
                          .Select(s => $"{s.Name} {s.IsEnabled()}").ToArray();

            return(sources);
        }
Example #14
0
 public CustomEventListener()
     : base()
 {
     this.EnableEvents(
         (from @event in EventSource.GetSources()
          where @event.Guid == EventSource.GetGuid(typeof(CustomEventSource))
          select @event).Single(), EventLevel.Informational);
 }
Example #15
0
            public TPLListener()
            {
                var tplEventSource = EventSource
                                     .GetSources()
                                     .First(e => e.Name == "System.Threading.Tasks.TplEventSource");

                EnableEvents(tplEventSource, EventLevel.LogAlways);
            }
Example #16
0
        private void ShowSources()
        {
            var sources = EventSource.GetSources();

            foreach (var source in sources)
            {
                Console.WriteLine("Source: {0}, {1}", source.Name, source.Guid);
            }
        }
Example #17
0
        public ConsoleEventListener(string filter)
        {
            _eventFilter = filter ?? throw new ArgumentNullException(nameof(filter));

            foreach (EventSource source in EventSource.GetSources())
            {
                EnableEvents(source, EventLevel.LogAlways);
            }
        }
Example #18
0
 private static EventSource FindEventSource(string name)
 {
     foreach (var eventSource in EventSource.GetSources())
     {
         if (string.Equals(eventSource.Name, name))
         {
             return(eventSource);
         }
     }
     return(default);
            public LogEventListener(string name, EventLevel eventLevel = EventLevel.LogAlways, EventKeywords eventKeywords = EventKeywords.All)
            {
                _name          = name;
                _eventLevel    = eventLevel;
                _eventKeywords = eventKeywords;

                foreach (var source in EventSource.GetSources())
                {
                    OnEventSourceCreated(source);
                }
            }
Example #20
0
        private static void SetUpEventSourceLog()
        {
            var telemetryEventSource = EventSource.GetSources()
                                       .FirstOrDefault(es => es.Name == "Microsoft-ApplicationInsights-Core");

            if (telemetryEventSource != null)
            {
                var myEventListener = new MyEventListener();
                myEventListener.EnableEvents(telemetryEventSource, EventLevel.LogAlways);
            }
        }
Example #21
0
        static void Main(string[] args)
        {
            IEnumerable <EventSource> eventSources = EventSource.GetSources();

            InitListener(eventSources);

            WriteLine($"Log Guid: {SampleEventSource.Log.Guid}");
            WriteLine($"Name: {SampleEventSource.Log.Name}");
            ParallelRequestSample();
            ReadLine();
        }
Example #22
0
        /// <summary>
        /// Get the event source with a given name.
        /// </summary>
        /// <param name="name">Name of the event source.</param>
        /// <returns>The EventSource, if it exists, or null.</returns>
        public static EventSource FindEventSource(string name)
        {
            foreach (var src in EventSource.GetSources())
            {
                if (string.Compare(name, src.Name, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    return(src);
                }
            }

            return(null);
        }
Example #23
0
        /// <summary>
        /// Get the event source with a given GUID.
        /// </summary>
        /// <param name="providerId">GUID of the event source.</param>
        /// <returns>The EventSource, if it exists, or null.</returns>
        public static EventSource FindEventSource(Guid providerId)
        {
            foreach (var src in EventSource.GetSources())
            {
                if (providerId == src.Guid)
                {
                    return(src);
                }
            }

            return(null);
        }
Example #24
0
        public bool AddEventSource(Guid sourceGuid)
        {
            var matchedEventSource = EventSource.GetSources().SingleOrDefault(eventSource => eventSource.Guid.Equals(sourceGuid));

            if (matchedEventSource == default(EventSource))
            {
                return(false);
            }

            this.EnableEvents(matchedEventSource, EventLevel.LogAlways);
            return(true);
        }
Example #25
0
        static void Main()
        {
            string name = MyAdvancedProjectEventSource.GetName(typeof(MyAdvancedProjectEventSource));
            // IEnumerable<EventSource> eventSources = MyProjectEventSource.GetSources();
            IEnumerable <EventSource> eventSources = EventSource.GetSources();

            InitListener(eventSources);
            //  MyProjectEventSource.Log.Startup();
            MyAdvancedProjectEventSource.Log.Startup();
            MyAdvancedProjectEventSource.Log.SomeTask();
            MyAdvancedProjectEventSource.Log.Startup2();
            NetworkRequestSample();
            Console.ReadLine();
            listener.Dispose();
        }
Example #26
0
        public Task StartAsync(CancellationToken cancellationToken)
        {
            _poll = Task.Run(async() =>
            {
                while (!cancellationToken.IsCancellationRequested)
                {
                    foreach (var eventSource in EventSource.GetSources())
                    {
                        OnEventSourceCreated(eventSource);
                    }

                    await Task.Delay(1000, cancellationToken);
                }
            }, cancellationToken);

            return(Task.CompletedTask);
        }
Example #27
0
        /// <summary>
        /// Confirms that there are no EventSources running.
        /// </summary>
        /// <param name="message">Will be printed as part of the Assert</param>
        public static void CheckNoEventSourcesRunning(string message = "")
        {
            var eventSources = EventSource.GetSources();

            string eventSourceNames = "";

            foreach (var eventSource in EventSource.GetSources())
            {
                if (eventSource.Name != "System.Threading.Tasks.TplEventSource" &&
                    eventSource.Name != "System.Diagnostics.Eventing.FrameworkEventSource")
                {
                    eventSourceNames += eventSource.Name + " ";
                }
            }

            Debug.WriteLine(message);
            Assert.Equal("", eventSourceNames);
        }
Example #28
0
        void RefreshDiagnosticSource()
        {
            var diagSource = EventSource.GetSources().FirstOrDefault(x => x.Name == "Microsoft-Diagnostics-DiagnosticSource");

            if (diagSource == null)
            {
                return;
            }

            listener.DisableEvents(diagSource);
            if (enabledSources.Count > 0)
            {
                listener.EnableEvents(diagSource, EventLevel.Informational, EventKeywords.All, new Dictionary <string, string>
                {
                    { "FilterAndPayloadSpecs", string.Join(Environment.NewLine, enabledSources) }
                });
            }
        }
Example #29
0
        public void Disable(string source)
        {
            enabledSources.Remove(source);

            var evtSource   = EventSource.GetSources().FirstOrDefault(x => x.Name == source);
            var traceSource = traceSources.Where(x => x.IsAlive).Select(x => x.Target as TraceSource).FirstOrDefault(x => x?.Name == source);

            if (evtSource != null)
            {
                listener.DisableEvents(evtSource);
            }

            RefreshDiagnosticSource();

            if (traceSource != null)
            {
                traceSource.Switch.Level = SourceLevels.Information;
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RingMasterClientUnitTest"/> class.
        /// </summary>
        public RingMasterClientUnitTest()
        {
            this.serverTransport  = new SimpleTransport();
            this.backend          = this.CreateBackend();
            this.ringMasterServer = new RingMasterServer(this.protocol, null, this.cancellationTokenSource.Token);
            this.ringMasterServer.RegisterTransport(this.serverTransport);
            this.ringMasterServer.OnInitSession = initRequest =>
            {
                return(new CoreRequestHandler(this.backend, initRequest));
            };

            foreach (var source in EventSource.GetSources())
            {
                if (source.Guid == this.ringMasterClientEventSourceGuid)
                {
                    Trace.TraceInformation($"Enabling EventSource {source.Name}");
                    this.listener.EnableEvents(source, EventLevel.Verbose);
                }
            }
        }