internal void RegisterServices(IServiceCollection services) { services.AddSingleton(Type, Factory); services.AddSingleton(typeof(IEventListener), sp => sp.GetService(Type)); // Register each events interface exposed at the level specified foreach (var i in EventParserTypes.GetEventInterfacesForCurrentRuntime(Type, Level)) { services.AddSingleton(i, sp => sp.GetService(Type)); } }
public void When_Calling_GetEventParsers_Then_Returns_All_Event_Parsers_Defined_In_The_DotNetRuntime_Library() { var parsers = EventParserTypes.GetEventParsers(); Assert.That(parsers, Is.SupersetOf(new[] { typeof(GcEventParser), typeof(JitEventParser), typeof(ThreadPoolEventParser), typeof(RuntimeEventParser), typeof(ContentionEventParser), typeof(ExceptionEventParser) })); }
public void Given_A_Type_That_Implements_All_IEvent_Interfaces_When_Calling_GetLevelsFromType_Then_Returns_All_Interfaces_Except_IEvents() { var levels = EventParserTypes.GetLevelsFromParser(typeof(AllEvents)); Assert.That(levels, Is.EquivalentTo(new[] { EventLevel.LogAlways, EventLevel.Verbose, EventLevel.Informational, EventLevel.Warning, EventLevel.Error, EventLevel.Critical })); }
public static ListenerRegistration Create <T>(CaptureLevel level, Func <IServiceProvider, T> factory) where T : IEventListener { var supportedLevels = EventParserTypes.GetLevelsFromParser(typeof(T)); var eventLevel = level.ToEventLevel(); if (!supportedLevels.Contains(eventLevel)) { throw new UnsupportedEventParserLevelException(typeof(T), level, supportedLevels); } return(new ListenerRegistration(eventLevel, typeof(T), sp => (object)factory(sp))); }
public void Given_A_Type_That_Implements_All_IEvent_Interfaces_When_Calling_GetEventInterfaces_Then_Returns_All_Interfaces_Except_IEvents() { var interfaces = EventParserTypes.GetEventInterfaces(typeof(AllEvents)); Assert.That(interfaces, Is.EquivalentTo(new[] { typeof(AllEvents.Events.Verbose), typeof(AllEvents.Events.Info), typeof(AllEvents.Events.Warning), typeof(AllEvents.Events.Error), typeof(AllEvents.Events.Always), typeof(AllEvents.Events.Critical), typeof(AllEvents.Events.Counters) })); }
public void When_Calling_GetEventInterfacesForCurrentRuntime_On_Net50_Then_Returns_Interfaces_For_Net50_Runtime_And_Below() { var interfaces = EventParserTypes.GetEventInterfacesForCurrentRuntime(typeof(VersionedEvents), EventLevel.LogAlways); Assert.That(interfaces, Is.EquivalentTo(new [] { typeof(VersionedEvents.Events.Counters), typeof(VersionedEvents.Events.CountersV3_1), typeof(VersionedEvents.Events.CountersV5_0) })); }
public UnsupportedEventParserRuntimeException(Type type) : base($"{EventParserTypes.AreEventsSupportedByRuntime(type)}") { Type = type; }