private static void RegisterNativeConfigurationFile(ILogServiceCollection services, IOptions <Log4NetSinkOptions> settings) { var filePath = settings.Value.NativeConfigFilePath; var needWatch = settings.Value.WatchNativeConfigFile; if (string.IsNullOrWhiteSpace(filePath)) { return; } services.AddOriginalConfigAction(__loadingAndConfiguringConfigurationPath); // ReSharper disable once InconsistentNaming void __loadingAndConfiguringConfigurationPath(IConfiguration _) { if (!File.Exists(filePath)) { return; } var loggerRepository = LogManager.GetRepository(Assembly.GetEntryAssembly()); if (needWatch) { XmlConfigurator.ConfigureAndWatch(loggerRepository, new FileInfo(filePath)); } else { XmlConfigurator.Configure(loggerRepository, new FileInfo(filePath)); } } }
private static void AddTraceIdGenerator(this ILogServiceCollection services) { services.AddDependency(s => s.TryAddScoped <FallbackTraceIdAccessor, FallbackTraceIdAccessor>()); if (!ExpectedTraceIdGeneratorName.HasValue()) { services.AddDependency(s => s.TryAddScoped <ILogTraceIdGenerator, IServiceProvider>(__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); } }
/// <summary> /// Register System TraceId generator for Autofac /// </summary> /// <param name="services"></param> /// <returns></returns> /// <exception cref="ArgumentNullException"></exception> public static ILogServiceCollection RegisterSystemTraceIdGenerator(this ILogServiceCollection services) { if (services is null) { throw new ArgumentNullException(nameof(services)); } if (!ExpectedTraceIdGeneratorName.HasValue()) { services.AddDependency(s => s.AddScoped <ILogTraceIdGenerator, IComponentContext>(__traceIdGeneratorFactory)); ExpectedTraceIdGeneratorName.Value = nameof(SystemTraceIdGenerator); } // ReSharper disable once InconsistentNaming ILogTraceIdGenerator __traceIdGeneratorFactory(IComponentContext provider) { //1. Get traceIdAccessor and fallbackTraceIdAccessor from ServiceProvider var traceIdAccessor = provider.ResolveOptional <TraceIdAccessor>(); var fallbackAccessor = provider.Resolve <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); } return(services); }
internal static void AllDone(ILogServiceCollection services) { if (services is ConsoleLogServiceCollection loggingServices) { using (loggingServices) { loggingServices.ActiveConsolePreferencesRenderers(); loggingServices.RegisterCoreComponents(); loggingServices.BuildAndActiveConfiguration(); loggingServices.AddTraceIdGenerator(); } ServiceResolver = loggingServices.OriginalServices.ToServiceContext().Build(); loggingServices.ActiveLogEventEnrichers(); StaticServiceResolver.SetResolver(ServiceResolver.ResolveRequired <ILoggingServiceProvider>()); } else { throw new ArgumentException(nameof(services)); } }
/// <summary> /// Add NodaTime integration /// </summary> /// <param name="services"></param> /// <param name="provider"></param> /// <returns></returns> /// <exception cref="ArgumentNullException"></exception> public static ILogServiceCollection AddNodaTimeIntegration(this ILogServiceCollection services, IDateTimeZoneProvider provider) { if (services is null) { throw new ArgumentNullException(nameof(services)); } if (provider is null) { throw new ArgumentNullException(nameof(provider)); } services.AsScalar <Offset>(); services.AsScalar <CalendarSystem>(); services.With <InstantDestructureResolveRule>(); services.With <LocalDateDestructureResolveRule>(); services.With <LocalDateTimeDestructureResolveRule>(); services.With <LocalTimeDestructureResolveRule>(); services.With <OffsetDateTimeDestructureResolveRule>(); services.With <DateTimeZoneDestructureResolveRule>(); services.With(new ZonedDateTimeDestructureResolveRule(provider)); services.With <DurationDestructureResolveRule>(); services.With <PeriodDestructureResolveRule>(); services.With <IntervalDestructureResolveRule>(); return(services); }
/// <summary> /// Done /// </summary> /// <param name="services"></param> /// <returns></returns> public static ContainerBuilder Done(this ILogServiceCollection services) { if (services is null) { throw new ArgumentNullException(nameof(services)); } if (services is AutofacServiceCollection loggingServices) { var builder = loggingServices.OriginalServices; using (loggingServices) { loggingServices.RegisterCoreComponents(); loggingServices.BuildAndActiveConfiguration(); loggingServices.RegisterTraceIdGenerator(); loggingServices.RegisterPostBuiltAction(); } return(builder); } throw new ArgumentException("Unknown type of ILogServiceCollection"); }
public static ILogServiceCollection AddExceptionless(this ILogServiceCollection services, IOptions <ExceptionlessSinkOptions> settings, Action <IConfiguration, ExceptionlessSinkConfiguration> configAct = null) { services.AddSinkSettings <ExceptionlessSinkOptions, ExceptionlessSinkConfiguration>(settings.Value, (conf, sink) => configAct?.Invoke(conf, sink)); services.AddDependency(s => { s.AddScoped <ILogPayloadClient, ExceptionlessPayloadClient>(); s.AddSingleton <ILogPayloadClientProvider, ExceptionlessPayloadClientProvider>(); s.TryAdd(ServiceDescriptor.Singleton(settings)); }); if (!string.IsNullOrWhiteSpace(settings.Value.OriginConfigFilePath)) { services.ModifyConfigurationBuilder(b => b.AddFile(settings.Value.OriginConfigFilePath, settings.Value.OriginConfigFileType)); services.AddOriginConfigAction(root => ExceptionlessClient.Default.Configuration.ReadFromConfiguration(root)); } else if (services.BeGivenConfigurationBuilder || services.BeGivenConfigurationRoot) { services.AddOriginConfigAction(root => ExceptionlessClient.Default.Configuration.ReadFromConfiguration(root)); } if (!string.IsNullOrWhiteSpace(settings.Value.ApiKey)) { services.AddOriginConfigAction(root => ExceptionlessClient.Default.Startup(settings.Value.ApiKey)); } else { services.AddOriginConfigAction(root => ExceptionlessClient.Default.Startup()); } RegisterCoreComponentsTypes(); return(services); }
/// <summary> /// To global /// </summary> /// <param name="services"></param> /// <param name="settingsAct"></param> /// <returns></returns> public static ILogServiceCollection ToGlobal(this ILogServiceCollection services, Action <LoggingOptions> settingsAct) { var settings = new LoggingOptions(); settingsAct?.Invoke(settings); return(ToGlobal(services, settings)); }
/// <summary> /// Done /// </summary> /// <param name="services"></param> /// <returns></returns> public static IServiceCollection Done(this ILogServiceCollection services) { if (services is null) { throw new ArgumentNullException(nameof(services)); } if (services is StandardLogServiceCollection loggingServices) { var builder = loggingServices.OriginalServices; using (loggingServices) { loggingServices.RegisterCoreComponents(); loggingServices.BuildAndActiveConfiguration(); loggingServices.RegisterTraceIdGenerator(); loggingServices.RegisterLoggerFactory(); loggingServices.RegisterCallback(); } return(builder); } throw new ArgumentException("Unknown type of ILogServiceCollection"); }
/// <summary> /// Add Log4Net support for Cosmos.Logging /// </summary> /// <param name="services"></param> /// <param name="settingAct"></param> /// <param name="configAct"></param> /// <returns></returns> public static ILogServiceCollection AddLog4Net(this ILogServiceCollection services, Action <Log4NetSinkOptions> settingAct = null, Action <IConfiguration, Log4NetSinkConfiguration> configAct = null) { var settings = new Log4NetSinkOptions(); settingAct?.Invoke(settings); return(services.AddLog4Net(settings, configAct)); }
/// <summary> /// Add TomatoLog for Cosmos.Logging /// </summary> /// <param name="services"></param> /// <param name="settingAct"></param> /// <param name="configAct"></param> /// <returns></returns> public static ILogServiceCollection AddTomatoLog(this ILogServiceCollection services, Action <TomatoLogSinkOptions> settingAct = null, Action <IConfiguration, TomatoLogSinkConfiguration> configAct = null) { var settings = new TomatoLogSinkOptions(); settingAct?.Invoke(settings); return(services.AddTomatoLog(settings, configAct)); }
public static ILogServiceCollection AddExceptionless(this ILogServiceCollection services, Action <ExceptionlessSinkOptions> settingAct = null, Action <IConfiguration, ExceptionlessSinkConfiguration> configAct = null) { var settings = new ExceptionlessSinkOptions(); settingAct?.Invoke(settings); return(services.AddExceptionless(settings, configAct)); }
/// <summary> /// To global /// </summary> /// <param name="services"></param> /// <param name="settingsAct"></param> /// <typeparam name="TLoggingSettings"></typeparam> /// <returns></returns> public static ILogServiceCollection ToGlobal <TLoggingSettings>(this ILogServiceCollection services, Action <TLoggingSettings> settingsAct) where TLoggingSettings : LoggingOptions, new() { var settings = new TLoggingSettings(); settingsAct?.Invoke(settings); return(ToGlobal(services, settings)); }
private static void RegisterCoreComponents(ILogServiceCollection services, IOptions <ConsoleSinkOptions> settings) { services.AddDependency(s => { s.AddScoped <ILogPayloadClient, ConsolePayloadClient>(); s.AddSingleton <ILogPayloadClientProvider, ConsolePayloadClientProvider>(); s.TryAdd(ServiceDescriptor.Singleton(settings)); }); }
/// <summary> /// Add console sink for Cosmos.Logging /// </summary> /// <param name="services"></param> /// <param name="settingAct"></param> /// <param name="configAction"></param> /// <returns></returns> public static ILogServiceCollection AddConsole(this ILogServiceCollection services, Action <ConsoleSinkOptions> settingAct = null, Action <IConfiguration, ConsoleSinkConfiguration> configAction = null) { var settings = new ConsoleSinkOptions(); settingAct?.Invoke(settings); return(services.AddConsole(settings, configAction)); }
/// <summary> /// Add file log for Cosmos.Logging /// </summary> /// <param name="services"></param> /// <param name="settingAct"></param> /// <param name="config"></param> /// <returns></returns> public static ILogServiceCollection AddFilelog(this ILogServiceCollection services, Action <FileSinkOptions> settingAct = null, Action <IConfiguration, FileSinkLogConfiguration> config = null) { var options = new FileSinkOptions(); settingAct?.Invoke(options); return(services.AddFilelog(Options.Create(options), config)); }
/// <summary> /// Add Tencent Cloud CLS support for Cosmos.Logging /// </summary> /// <param name="services"></param> /// <param name="settingAct"></param> /// <param name="configAct"></param> /// <returns></returns> public static ILogServiceCollection AddTencentCloudCls(this ILogServiceCollection services, Action <TencentCloudClsSinkOptions> settingAct = null, Action <IConfiguration, TencentCloudClsSinkConfiguration> configAct = null) { var settings = new TencentCloudClsSinkOptions(); settingAct?.Invoke(settings); return(services.AddTencentCloudCls(settings, configAct)); }
public static ILogServiceCollection RunsOnConsole(this ILogServiceCollection services, Action <LoggingOptions> settingsAction) { if (services.ExposeLogSettings() is LoggingOptions settings) { settingsAction?.Invoke(settings); } return(services.RegisterToRunsOnConsole()); }
/// <summary> /// Register Microsoft ASP.NET Core Trace Id generator /// </summary> /// <param name="services"></param> /// <returns></returns> public static ILogServiceCollection RegisterAspNetCoreTraceIdGenerator(this ILogServiceCollection services) { if (!ExpectedTraceIdGeneratorName.HasValue()) { services.AddDependency(s => s.AddScoped <ILogTraceIdGenerator, AspNetCoreTraceIdGenerator>()); ExpectedTraceIdGeneratorName.Value = nameof(AspNetCoreTraceIdGenerator); } return(services); }
private static void RegisterSqlSugarInterceptor(ILogServiceCollection services, IOptions <SqlSugarEnricherOptions> settings) { services.AddDependency(s => s.TryAddSingleton <IServiceProvider>(__sqlsugarInterceptorFactory, typeof(SqlSugarInterceptorDescriptor))); // ReSharper disable once InconsistentNaming object __sqlsugarInterceptorFactory(IServiceProvider provider) { return(new SqlSugarInterceptorDescriptor(provider.GetService <ILoggingServiceProvider>(), settings)); } }
private static void RegisterFreeSqlInterceptor(ILogServiceCollection services, IOptions <FreeSqlEnricherOptions> settings) { services.AddDependency(s => s.TryAdd(ServiceDescriptor.Singleton(typeof(FreeSqlInterceptorDescriptor), __freesqlInterceptorFactory))); // ReSharper disable once InconsistentNaming object __freesqlInterceptorFactory(IServiceProvider provider) { return(new FreeSqlInterceptorDescriptor(provider.GetService <ILoggingServiceProvider>(), settings)); } }
private static void RegisterNHibernateInitialization(ILogServiceCollection services, IOptions <NhEnricherOptions> settings) { services.AddDependency(s => s.TryAddSingleton <IServiceProvider>(__nhibernateInitFactory, typeof(StaticServiceResolveInitialization))); // ReSharper disable once InconsistentNaming object __nhibernateInitFactory(IServiceProvider provider) { return(new StaticServiceResolveInitialization(provider.GetRequiredService <ILoggingServiceProvider>(), settings.Value)); } }
public static ILogServiceCollection RunsOnConsole <TLoggingSettings>(this ILogServiceCollection services, TLoggingSettings settings) where TLoggingSettings : LoggingOptions, new() { if (services is ConsoleLogServiceCollection collection) { collection.ReplaceSettings(settings); } return(services.RegisterToRunsOnConsole()); }
/// <summary> /// To global /// </summary> /// <param name="services"></param> /// <param name="settings"></param> /// <typeparam name="TLoggingSettings"></typeparam> /// <returns></returns> public static ILogServiceCollection ToGlobal <TLoggingSettings>(this ILogServiceCollection services, TLoggingSettings settings) where TLoggingSettings : LoggingOptions, new() { if (services is AspNetLogServiceCollection collection) { collection.ReplaceSettings(settings); } return(services); }
/// <summary> /// To global /// </summary> /// <param name="services"></param> /// <param name="settings"></param> /// <typeparam name="TLoggingSettings"></typeparam> /// <returns></returns> public static ILogServiceCollection ToGlobal <TLoggingSettings>(this ILogServiceCollection services, TLoggingSettings settings) where TLoggingSettings : LoggingOptions, new() { if (services is ZkWebLogServiceCollection loggingServices) { loggingServices.ReplaceSettings(settings); } return(services); }
/// <summary> /// Add database integration /// </summary> /// <param name="service"></param> /// <param name="integrationAct"></param> /// <returns></returns> /// <exception cref="ArgumentNullException"></exception> public static ILogServiceCollection AddDatabaseIntegration(this ILogServiceCollection service, Action <DatabaseIntegration> integrationAct) { if (integrationAct == null) { throw new ArgumentNullException(nameof(integrationAct)); } var integration = new DatabaseIntegration(service); integrationAct.Invoke(integration); return(service); }
private static void RegisterApiKey(ILogServiceCollection services, string apiKey) { if (!string.IsNullOrWhiteSpace(apiKey)) { services.AddOriginalConfigAction(root => ExceptionlessClient.Default.Startup(apiKey)); } else { services.AddOriginalConfigAction(root => ExceptionlessClient.Default.Startup()); } }
/// <summary> /// Add console sink for Cosmos.Logging /// </summary> /// <param name="services"></param> /// <param name="settings"></param> /// <param name="configAction"></param> /// <returns></returns> public static ILogServiceCollection AddConsole(this ILogServiceCollection services, IOptions <ConsoleSinkOptions> settings, Action <IConfiguration, ConsoleSinkConfiguration> configAction = null) { RegisterConfiguration(services, settings, configAction); RegisterCoreComponents(services, settings); RegisterCoreComponentsTypes(); return(services); }
private static void RegisterOriginalConfig(ILogServiceCollection services, string path, FileTypes fileType) { if (!string.IsNullOrWhiteSpace(path)) { services.ModifyConfigurationBuilder(b => ConfigLoadingContext.Load(b, path, fileType)); services.AddOriginalConfigAction(root => ExceptionlessClient.Default.Configuration.ReadFromConfiguration(root)); } else if (services.BeGivenConfigurationBuilder || services.BeGivenConfigurationRoot) { services.AddOriginalConfigAction(root => ExceptionlessClient.Default.Configuration.ReadFromConfiguration(root)); } }
/// <summary> /// Add CorrelationId Integration /// </summary> /// <param name="service"></param> /// <returns></returns> /// <exception cref="ArgumentNullException"></exception> public static ILogServiceCollection AddCorrelationIdIntegration(this ILogServiceCollection service) { if (service is null) { throw new ArgumentNullException(nameof(service)); } service.AddDependency(s => s.TryAdd(ServiceDescriptor.Scoped <ILogTraceIdGenerator, CorrelationIdGenerator>())); ExpectedTraceIdGeneratorName.Value = nameof(CorrelationIdGenerator); return(service); }