private static void RegisterTraceIdGenerator(this AspNetLogServiceCollection serviceImpl)
        {
            serviceImpl.AddDependency(s => s.TryAdd(ServiceDescriptor.Scoped <FallbackTraceIdAccessor, FallbackTraceIdAccessor>()));

            if (!ExpectedTraceIdGeneratorName.HasValue())
            {
                serviceImpl.AddDependency(s => s.TryAdd(ServiceDescriptor.Scoped(__traceIdGeneratorFactory)));
                ExpectedTraceIdGeneratorName.Value = nameof(SystemTraceIdGenerator);
            }

            // ReSharper disable once InconsistentNaming
            ILogTraceIdGenerator __traceIdGeneratorFactory(IServiceProvider provider)
            {
                //1. Get traceIdAccessor and fallbackTraceIdAccessor from ServiceProvider
                var traceIdAccessor  = provider.GetService <TraceIdAccessor>();
                var fallbackAccessor = provider.GetRequiredService <FallbackTraceIdAccessor>();

                //2. Create a new instance of SystemTraceIdGenerator
                var generator = new SystemTraceIdGenerator(traceIdAccessor, fallbackAccessor);

                //3. Scoped update
                LogTraceIdGenerator.ScopedUpdate(generator);

                //4. Done, and return.
                return(generator);
            }
        }
Example #2
0
 private static void RegisterCoreComponents(AspNetLogServiceCollection serviceImpl)
 {
     serviceImpl.AddDependency(s => s.AddSingleton <ILoggingServiceProvider, AspNetLoggingServiceProvider>());
     serviceImpl.BuildConfiguration();
     serviceImpl.ActiveSinkSettings();
     serviceImpl.ActiveOriginConfiguration();
     serviceImpl.AddDependency(s => s.AddSingleton(Options.Create((LoggingOptions)serviceImpl.ExposeLogSettings())));
     serviceImpl.AddDependency(s => s.AddSingleton(serviceImpl.ExposeLoggingConfiguration()));
 }