Ejemplo n.º 1
0
            protected override void When()
            {
                var current    = this.configuration.SinkSettings[0];
                var newSources = new List <EventSourceSettings>(current.EventSources);

                newSources.Add(new EventSourceSettings(EventSource.GetName(typeof(TestEventSource))));
                var newSink = new SinkSettings(current.Name, current.Sink, newSources);

                // will trigger changed event
                this.configuration.SinkSettings.Remove(current);
                this.configuration.SinkSettings.Add(newSink);

                // We expect 2 events
                this.inMemoryListener.WaitSignalCondition = () => inMemoryListener.EventWrittenCount == 2;
            }
Ejemplo n.º 2
0
            protected override void Given()
            {
                base.Given();
                inMemoryListener.WaitSignalCondition = () => inMemoryListener.EventWrittenCount == 2;
                var sink = new Lazy <IObserver <EventEntry> >(() => inMemoryListener);
                var localSourceSettings = new EventSourceSettings(EventSource.GetName(typeof(TestEventSource)));

                this.eventSources.Add(localSourceSettings);
                sinkSettings = new List <SinkSettings> {
                    new SinkSettings("test", sink, eventSources)
                };
                configuration = new TraceEventServiceConfiguration(sinkSettings);
                this.sut      = new TraceEventService(configuration);
                this.sut.Start();
            }
            protected override void Given()
            {
                this.domain1 = new DisposableDomain();
                this.domain2 = new DisposableDomain();

                var initialManifest = EventSource.GenerateManifest(typeof(MyNewCompanyEventSource), null);

                this.sourceSettings = new EventSourceSettings(EventSource.GetName(typeof(MyNewCompanyEventSource)));
                base.Given();

                // We expect 2 events
                this.inMemoryListener.WaitSignalCondition = () => inMemoryListener.EventWrittenCount == 2;

                this.sut.Start();
            }
Ejemplo n.º 4
0
            protected override void Given()
            {
                base.Given();
                var sink = new Lazy <IObserver <EventEntry> >(() => inMemoryListener);

                sourceSettings = new EventSourceSettings(EventSource.GetName(typeof(MyCompanyEventSource)), level: EventLevel.Warning, matchAnyKeyword: MyCompanyEventSource.Keywords.Diagnostic);
                eventSources   = new List <EventSourceSettings> {
                    sourceSettings
                };
                sinkSettings = new List <SinkSettings> {
                    new SinkSettings("test", sink, eventSources)
                };
                configuration = new TraceEventServiceConfiguration(sinkSettings);
                this.sut      = new TraceEventService(configuration);
                this.sut.Start();
            }
Ejemplo n.º 5
0
        internal static string GetName(Type eventSourceType)
        {
#if USE_EVENTSOURCE_REFLECTION
            var loadFromEvtSrcType = GetBaseEventSourceType(eventSourceType);

            MethodInfo mi = loadFromEvtSrcType.GetMethod("GetName", BindingFlags.Static | BindingFlags.Public,
                                                         null, new Type[] { typeof(Type) }, null);
            if (mi == null)
            {
                throw new ApplicationException(string.Format("Base EventSource type does not implement expected GetName() method (processing {0}).", eventSourceType.FullName));
            }
            string name = (string)mi.Invoke(null, new object[] { eventSourceType });
            return(name);
#else
            return(EventSource.GetName(eventSourceType));
#endif
        }
            protected override void Given()
            {
                base.Given();
                var sink = new Lazy <IObserver <EventEntry> >(() => inMemoryListener);

                this.SourceSettingsConfig = new EventSourceSettingsConfig(EventSource.GetName(typeof(MyCompanyEventSource)), level: EventLevel.Warning);
                eventSources = new List <EventSourceSettingsConfig>()
                {
                    { this.SourceSettingsConfig }
                };
                sinkSettings = new List <SinkSettings>()
                {
                    { new SinkSettings("test", sink, eventSources) }
                };
                configuration = new TraceEventServiceConfiguration(sinkSettings);
                this.Sut      = new TraceEventService(configuration);
                this.Sut.Start();
            }
Ejemplo n.º 7
0
            protected override void Given()
            {
                RemoveAnyExistingSession(SessionName2);
                base.Given();

                inMemoryListener2 = new InMemoryEventListener(formatter);
                var sink = new Lazy <IObserver <EventEntry> >(() => inMemoryListener2);
                var localSourceSettings = new EventSourceSettings(EventSource.GetName(typeof(MyCompanyEventSource)), level: EventLevel.Informational, matchAnyKeyword: MyCompanyEventSource.Keywords.Page);
                var localEventSources   = new List <EventSourceSettings> {
                    localSourceSettings
                };
                var localSinkSettings = new List <SinkSettings> {
                    new SinkSettings("test", sink, localEventSources)
                };
                var localConfiguration = new TraceEventServiceConfiguration(localSinkSettings, new TraceEventServiceSettings {
                    SessionNamePrefix = SessionName2
                });

                this.sut2 = new TraceEventService(localConfiguration);
            }
Ejemplo n.º 8
0
            protected override void Given()
            {
                base.Given();
                inMemoryListener = new InMemoryEventListener(new MockFormatter {
                    BeforeWriteEventAction = f => { throw new Exception("unhandled_exception_test"); }
                });
                var sink = new Lazy <IObserver <EventEntry> >(() => inMemoryListener);

                sourceSettings = new EventSourceSettings(EventSource.GetName(typeof(MyCompanyEventSource)));
                eventSources   = new List <EventSourceSettings> {
                    sourceSettings
                };
                sinkSettings = new List <SinkSettings> {
                    new SinkSettings("test", sink, eventSources)
                };
                configuration = new TraceEventServiceConfiguration(sinkSettings);
                this.sut      = new TraceEventService(configuration);

                slabListener = new InMemoryEventListener();
                slabListener.EnableEvents(SemanticLoggingEventSource.Log, EventLevel.Error, SemanticLoggingEventSource.Keywords.TraceEvent);
                this.sut.Start();
            }
            protected override void Given()
            {
                this.sourceSettings = new SemanticLogging.Etw.Configuration.EventSourceSettings(EventSource.GetName(typeof(DifferentEnumsEventSource)));
                base.Given();

                this.slabListener = new InMemoryEventListener();
                this.slabListener.EnableEvents(SemanticLoggingEventSource.Log, EventLevel.Error, SemanticLoggingEventSource.Keywords.TraceEvent);

                this.sut.Start();
            }
            protected override void When()
            {
                // We expect 3 events, 2 for listener1(Level=LogAlways) and 1 for listener2 (Level=Warning)
                inMemoryListener.WaitSignalCondition = () => inMemoryListener.EventWrittenCount == 3;

                var sink = new Lazy <IObserver <EventEntry> >(() => inMemoryListener);
                var localSourceSettings = new SemanticLogging.Etw.Configuration.EventSourceSettings(EventSource.GetName(typeof(MyCompanyEventSource)), level: EventLevel.Warning);
                var localEventSources   = new List <SemanticLogging.Etw.Configuration.EventSourceSettings> {
                    localSourceSettings
                };

                this.configuration.SinkSettings.Add(new SinkSettings("test2", sink, localEventSources));
            }
        protected override void Given()
        {
            TraceEventManifestsCache.Clear();

            this.formatter        = new MockFormatter();
            this.inMemoryListener = new InMemoryEventListener(this.formatter);
            var sink = new Lazy <IObserver <EventEntry> >(() => this.inMemoryListener);

            this.sourceSettings = this.sourceSettings ?? new SemanticLogging.Etw.Configuration.EventSourceSettings(EventSource.GetName(typeof(MyCompanyEventSource)));
            this.eventSources   = new List <SemanticLogging.Etw.Configuration.EventSourceSettings> {
                this.sourceSettings
            };
            this.sinkSettings = new List <SinkSettings> {
                new SinkSettings("test", sink, this.eventSources)
            };
            this.configuration = new TraceEventServiceConfiguration(sinkSettings, this.serviceSettings);

            try
            {
                this.sut = new TraceEventService(configuration);
            }
            catch (UnauthorizedAccessException uae)
            {
                Assert.Inconclusive(uae.Message);
            }

            // Clean up any previous unclosed session to avoid collisions
            this.RemoveAnyExistingSession();
        }
Ejemplo n.º 12
0
 public static bool IsDependencyTrackingEventSource(this EventSource eventSource)
 {
     return(string.Equals(eventSource.Name, EventSource.GetName(typeof(CosmosEventSource))));
 }
Ejemplo n.º 13
0
        public void Start()
        {
            etwSession = new TraceEventSession("RequestSession");
            etwSession.Source.Dynamic.All += HandleEtwEvent;
            var eventSourceProviderGuid = TraceEventProviders.GetEventSourceGuidFromName(EventSource.GetName(typeof(EtwSource)));

            etwSession.EnableProvider(eventSourceProviderGuid);
            Task.Factory.StartNew(() => etwSession.Source.Process());
        }
Ejemplo n.º 14
0
        public static void Run(bool workAround)
        {
            Console.WriteLine("");
            Console.WriteLine($"Running {nameof(Repro)} with {nameof(Repro)}={workAround}");
            var eventSourceName = EventSource.GetName(typeof(ReproEventSource));
            var sessionName     = eventSourceName;

            Console.WriteLine("Creating a '{0}' session", sessionName);
            using (var session = new TraceEventSession(sessionName))
            {
                bool isProcessing = false;
                Console.CancelKeyPress += (object sender, ConsoleCancelEventArgs e) => { session.Dispose(); };

                // Write events received and stop on StopEvent
                session.Source.Dynamic.All += (TraceEvent data) =>
                {
                    Console.WriteLine($"RECEIVED event {data.ID}");
                    if ((ushort)data.ID == ReproEventSource.Events.StopEvent)
                    {
                        Console.WriteLine($"End of {nameof(Repro)} - disposing session");
                        session.Dispose();
                    }
                };

                void EnableWithoutOptions()
                {
                    Console.WriteLine("Enabling provider WITHOUT options");
                    session.EnableProvider(eventSourceName);
                    Console.WriteLine("Provider enabled WITHOUT options");
                }

                void LoadEventSource()
                {
                    var dummy = ReproEventSource.Log;
                }

                void EnableWithOptions()
                {
                    Console.WriteLine("Enabling provider WITH options");
                    var options = new TraceEventProviderOptions();

                    options.EventIDsToEnable =
                        new int[] {
                        ReproEventSource.Events.Event1,
                        ReproEventSource.Events.StopEvent
                    };
                    session.EnableProvider(eventSourceName, options: options);
                    Console.WriteLine("Provider enabled WITH options");
                }

                void GenerateEvents()
                {
                    Task.Factory.StartNew(() =>
                    {
                        Console.WriteLine($"WRITING event {ReproEventSource.Events.Event1}");
                        ReproEventSource.Log.Event1();
                        Console.WriteLine($"WRITING event {ReproEventSource.Events.Event2}");
                        ReproEventSource.Log.Event2();
                        Console.WriteLine($"WRITING event {ReproEventSource.Events.StopEvent}");
                        ReproEventSource.Log.StopEvent();
                    });
                }

                void WaitALittle(TimeSpan timeSpan, string message)
                {
                    Console.WriteLine($"WAITING {timeSpan.ToString()} - {message}");
                    Thread.Sleep(timeSpan);
                    Console.WriteLine($"END WAITING {timeSpan.ToString()} - {message}");
                }

                void EnsureProcessing()
                {
                    if (!isProcessing)
                    {
                        Task.Factory.StartNew(() =>
                        {
                            WaitALittle(TimeSpan.FromMilliseconds(100), "before processing");
                            Console.WriteLine("Starting processing");
                            isProcessing = true;
                            session.Source.Process();
                        });
                    }
                }

                if (workAround)
                {
                    LoadEventSource();
                    EnableWithoutOptions();
                    EnsureProcessing();
                    WaitALittle(TimeSpan.FromSeconds(4), "processing warmup");
                }

                EnableWithOptions();
                EnsureProcessing();
                WaitALittle(TimeSpan.FromSeconds(4), "before generating events");
                GenerateEvents();
                WaitALittle(TimeSpan.FromSeconds(4), "processing events");
            }
        }
Ejemplo n.º 15
0
        public void EventSource_ExistsWithCorrectId()
        {
            Type esType = typeof(NetworkChange).Assembly.GetType("System.Net.NetEventSource", throwOnError: false, ignoreCase: false);

            if (esType != null)
            {
                Assert.Equal("Private.InternalDiagnostics.System.Net.NetworkInformation", EventSource.GetName(esType));
                Assert.Equal(Guid.Parse("e090a35b-1033-5de3-89e3-01cde7c158ce"), EventSource.GetGuid(esType));

                Assert.NotEmpty(EventSource.GenerateManifest(esType, esType.Assembly.Location));
            }
        }
 protected override void Given()
 {
     this.sourceSettings = new SemanticLogging.Etw.Configuration.EventSourceSettings(EventSource.GetName(typeof(LargeManifestEventSource)));
     base.Given();
     this.sut.Start();
 }
            protected override void Given()
            {
                this.domain1        = new DisposableDomain();
                this.domain2        = new DisposableDomain();
                this.sourceSettings = new SemanticLogging.Etw.Configuration.EventSourceSettings(EventSource.GetName(typeof(LargeManifestEventSource)));

                base.Given();

                // We expect 2 events
                this.inMemoryListener.WaitSignalCondition = () => inMemoryListener.EventWrittenCount == 2;

                this.sut.Start();
            }
Ejemplo n.º 18
0
 protected override void Given()
 {
     this.sourceSettings = new EventSourceSettings(EventSource.GetName(typeof(MultipleTypesEventSource)));
     base.Given();
     this.sut.Start();
 }
Ejemplo n.º 19
0
 /// <summary>
 /// get roslyn event source name
 /// </summary>
 public static string GetRoslynEventSourceName()
 {
     return(EventSource.GetName(typeof(RoslynEventSource)));
 }
Ejemplo n.º 20
0
 protected override void Given()
 {
     this.sourceSettings = new EventSourceSettings(EventSource.GetName(typeof(LargeManifestEventSource)));
     base.Given();
     this.sut.Start();
 }