/// <summary> /// Adds <c>ETW</c> in-process telemetry session services to the service collection. /// </summary> /// <param name="services">A <see cref="IServiceCollection"/> instance.</param> /// <param name="configuration">A <see cref="IConfiguration"/> instance.</param> /// <returns>The provided <see cref="IServiceCollection"/> instance.</returns> public static IServiceCollection AddInProcessTelemetrySession( this IServiceCollection services, IConfiguration configuration) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } SessionConfiguration sessionConfiguration = configuration .GetSection("Tracing") .Get <SessionConfiguration>(); return(services .AddTracingCore(configuration) .AddSingleton(sessionConfiguration) .AddSingleton <IProvidersDescriptor, SessionConfigurationProvidersDescriptor>() .AddSingleton(p => { IEnumerable <ITelemetryEventTransmitter> eventTransmitters = p.GetServices <ITelemetryEventTransmitter>(); ITelemetrySession session = InProcessTelemetrySession .Create(sessionConfiguration, p.GetServices <IProvidersDescriptor>()); foreach (ITelemetryEventTransmitter transmitter in eventTransmitters) { session.Attach(transmitter); } return session; })); }