/// <summary>
        /// For logging
        /// </summary>
        public static void UseMongoDb(
            this LoggingConfigurationBuilder builder,
            string mongoDbConnectionString,
            string logCollectionName)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }
            if (mongoDbConnectionString == null)
            {
                throw new ArgumentNullException("mongoDbConnectionString");
            }
            if (logCollectionName == null)
            {
                throw new ArgumentNullException("logCollectionName");
            }

            var mongoUrl = GetMongoUrl(mongoDbConnectionString);

            var database = new MongoClient(mongoUrl)
                           .GetServer()
                           .GetDatabase(mongoUrl.DatabaseName);

            UseMongoDbLoggerFactory(database, logCollectionName);
        }
예제 #2
0
 /// <summary>
 /// Add xml format configuration file by the given path.
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="path"></param>
 /// <returns></returns>
 /// <exception cref="ArgumentNullException"></exception>
 public static LoggingConfigurationBuilder AddXmlFile(this LoggingConfigurationBuilder builder, string path)
 {
     if (builder is null)
     {
         throw new ArgumentNullException(nameof(builder));
     }
     return(builder.Configure(b => b.AddXmlFile(path, true, true)));
 }
예제 #3
0
        protected BaseTest(Func <ILogAdapter, ILogAdapter> adapterFn)
        {
            var adapter = adapterFn(logCapture);

            testLogger        = adapter.Level(LogLevel.Debug).Logger("");
            testLogging       = Components.Logging(adapter).Level(LogLevel.Debug);
            BasicTaskExecutor = new TaskExecutor("test-sender", testLogger);
        }
        /// <summary>
        /// Writes Log Events to <see cref="System.Console"/>.
        /// </summary>
        /// <param name="builder">The <see cref="LoggingConfigurationBuilder" />.</param>
        /// <returns>The <see cref="LoggingConfigurationBuilder" />.</returns>
        public static LoggingConfigurationBuilder WriteToConsole([NotNull] this LoggingConfigurationBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(builder.RegisterSink(SinkName, new ConsoleLoggingSinkProvider(builder.SinkConfiguration.GetSection(SinkName))));
        }
        internal ZkWebLogServiceCollection()
        {
            _configurationBuilder             = new LoggingConfigurationBuilder();
            _configurationBuilderLockedStatus = false;
            _serviceCollection = new ServiceCollection();
            _settings          = new LoggingOptions();
            _sinkSettings      = new Dictionary <string, ILoggingSinkOptions>();

            BeGivenConfigurationBuilder = _configurationBuilder.InitializedByGivenBuilder;
            BeGivenConfigurationRoot    = false;
        }
        public static LoggingConfigurationBuilder WriteToSink([NotNull] this LoggingConfigurationBuilder builder, ILogEventSink logEventSink)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.LoggerConfiguration.WriteTo.Sink(logEventSink);

            return(builder);
        }
예제 #7
0
        internal ConsoleLogServiceCollection(IServiceCollection services, IConfigurationRoot root)
        {
            _configurationBuilder             = new DisabledConfigurationBuilder(root);
            _configurationBuilderLockedStatus = true;
            _serviceCollection = services ?? throw new ArgumentNullException(nameof(services));
            _settings          = new LoggingOptions();
            _sinkSettings      = new Dictionary <string, ILoggingSinkOptions>();

            BeGivenConfigurationBuilder = _configurationBuilder.InitializedByGivenBuilder;
            BeGivenConfigurationRoot    = true;
        }
        protected internal AspNetLogServiceCollection(IServiceCollection services, IConfigurationBuilder builder)
        {
            _configurationBuilder             = new LoggingConfigurationBuilder(builder);
            _configurationBuilderLockedStatus = false;
            _serviceCollection = services ?? throw new ArgumentNullException(nameof(services));
            _settings          = new LoggingOptions();
            _sinkSettings      = new Dictionary <string, ILoggingSinkOptions>();

            BeGivenConfigurationBuilder = _configurationBuilder.InitializedByGivenBuilder;
            BeGivenConfigurationRoot    = false;
        }
        /// <summary>
        /// ASP.NET Log service collection
        /// </summary>
        /// <param name="services"></param>
        /// <param name="root"></param>
        protected internal AspNetLogServiceCollection(IServiceCollection services, IConfigurationRoot root)
        {
            _configurationBuilder             = new DisabledConfigurationBuilder(root);
            _configurationBuilderLockedStatus = true;
            _serviceCollection           = services ?? throw new ArgumentNullException(nameof(services));
            _settings                    = new LoggingOptions();
            _sinkSettings                = new Dictionary <string, ILoggingSinkOptions>();
            _additionalEnricherProviders = new List <Func <ILogEventEnricher> >();

            BeGivenConfigurationBuilder = _configurationBuilder.InitializedByGivenBuilder;
            BeGivenConfigurationRoot    = true;
        }
        internal ConsoleLogServiceCollection(IServiceCollection services, IConfigurationBuilder builder)
        {
            _configurationBuilder             = new LoggingConfigurationBuilder(builder);
            _configurationBuilderLockedStatus = false;
            _services     = new MicrosoftProxyRegister(services ?? throw new ArgumentNullException(nameof(services)));
            _settings     = new LoggingOptions();
            _sinkSettings = new Dictionary <string, ILoggingSinkOptions>();
            _additionalEnricherProviders = new List <Func <ILogEventEnricher> >();

            BeGivenConfigurationBuilder = _configurationBuilder.InitializedByGivenBuilder;
            BeGivenConfigurationRoot    = false;
        }
        internal ZkWebLogServiceCollection()
        {
            _configurationBuilder             = new LoggingConfigurationBuilder();
            _configurationBuilderLockedStatus = false;
            _services     = new MicrosoftProxyRegister(new ServiceCollection());
            _settings     = new LoggingOptions();
            _sinkSettings = new Dictionary <string, ILoggingSinkOptions>();
            _additionalEnricherProviders = new List <Func <ILogEventEnricher> >();

            BeGivenConfigurationBuilder = _configurationBuilder.InitializedByGivenBuilder;
            BeGivenConfigurationRoot    = false;
        }
        /// <summary>
        /// Enrich Log Events with Application Metadata.
        /// </summary>
        /// <param name="builder">The <see cref="LoggingConfigurationBuilder"/>.</param>
        /// <returns>The <see cref="LoggingConfigurationBuilder" />.</returns>
        public static LoggingConfigurationBuilder EnrichWithApplicationMetadata([NotNull] this LoggingConfigurationBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.LoggerConfiguration.Enrich.WithProperty("ApplicationName", Hosting.ApplicationMetadata.Name);
            builder.LoggerConfiguration.Enrich.WithProperty("ApplicationVersion", Hosting.ApplicationMetadata.Version);

            return(builder);
        }
예제 #13
0
 /// <summary>
 /// Add xml format configuration by the given stream.
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="stream"></param>
 /// <returns></returns>
 /// <exception cref="ArgumentNullException"></exception>
 /// <exception cref="ArgumentException"></exception>
 public static LoggingConfigurationBuilder AddXmlStream(this LoggingConfigurationBuilder builder, Stream stream)
 {
     if (builder is null)
     {
         throw new ArgumentNullException(nameof(builder));
     }
     if (stream is null || !stream.CanRead)
     {
         throw new ArgumentException("Stream cannot be null or cannot be read.");
     }
     return(builder.Configure(b => b.AddXmlStream(stream)));
 }
예제 #14
0
 /// <summary>
 /// Add in-memory collection
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="inMemoryConfig"></param>
 /// <returns></returns>
 /// <exception cref="ArgumentNullException"></exception>
 public static LoggingConfigurationBuilder AddXmlDictionary(this LoggingConfigurationBuilder builder, Dictionary <string, string> inMemoryConfig)
 {
     if (builder is null)
     {
         throw new ArgumentNullException(nameof(builder));
     }
     if (inMemoryConfig is null)
     {
         throw new ArgumentNullException(nameof(inMemoryConfig));
     }
     return(builder.Configure(b => b.AddInMemoryCollection(inMemoryConfig)));
 }
        internal AutofacServiceCollection(ContainerBuilder services, IConfigurationRoot root)
        {
            _configurationBuilder = root is null
                ? new LoggingConfigurationBuilder()
                : new DisabledConfigurationBuilder(root);
            _configurationBuilderLockedStatus = root != null;
            _services     = new AutofacProxyRegister(services);
            _settings     = new LoggingOptions();
            _sinkSettings = new Dictionary <string, ILoggingSinkOptions>();
            _additionalEnricherProviders = new List <Func <ILogEventEnricher> >();

            BeGivenConfigurationBuilder = _configurationBuilder.InitializedByGivenBuilder;
            BeGivenConfigurationRoot    = root != null;
        }
예제 #16
0
        internal StandardLogServiceCollection(IServiceCollection services, IConfigurationRoot root)
        {
            _configurationBuilder = root is null
                ? new LoggingConfigurationBuilder()
                : new DisabledConfigurationBuilder(root);
            _configurationBuilderLockedStatus = root != null;
            _services     = new MicrosoftProxyRegister(services ?? throw new ArgumentNullException(nameof(services)));
            _settings     = new LoggingOptions();
            _sinkSettings = new Dictionary <string, ILoggingSinkOptions>();
            _additionalEnricherProviders = new List <Func <ILogEventEnricher> >();

            BeGivenConfigurationBuilder = _configurationBuilder.InitializedByGivenBuilder;
            BeGivenConfigurationRoot    = root != null;
        }
 internal ConfigurationBuilder(Configuration copyFrom)
 {
     _autoAliasingOptOut          = copyFrom.AutoAliasingOptOut;
     _dataSourceFactory           = copyFrom.DataSourceFactory;
     _diagnosticOptOut            = copyFrom.DiagnosticOptOut;
     _enableBackgroundUpdating    = copyFrom.EnableBackgroundUpdating;
     _evaluationReasons           = copyFrom.EvaluationReasons;
     _eventProcessorFactory       = copyFrom.EventProcessorFactory;
     _httpConfigurationBuilder    = copyFrom.HttpConfigurationBuilder;
     _loggingConfigurationBuilder = copyFrom.LoggingConfigurationBuilder;
     _mobileKey = copyFrom.MobileKey;
     _offline   = copyFrom.Offline;
     _persistenceConfigurationBuilder = copyFrom.PersistenceConfigurationBuilder;
     _serviceEndpointsBuilder         = new ServiceEndpointsBuilder(copyFrom.ServiceEndpoints);
 }
예제 #18
0
        /// <summary>
        /// Enrich Log Events with Activity Context.
        /// </summary>
        /// <param name="builder">The <see cref="LoggingConfigurationBuilder" /> on which to add the enricher.</param>
        /// <returns>The <see cref="LoggingConfigurationBuilder" /> so that additional calls can be chained.</returns>
        public static LoggingConfigurationBuilder EnrichWithActivityContext([NotNull] this LoggingConfigurationBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var activityContextAccessor = builder.Services.BuildServiceProvider().GetService <IActivityContextAccessor>();

            if (activityContextAccessor != null)
            {
                builder.LoggerConfiguration.Enrich.With(new ActivityContextEnricher(activityContextAccessor));
            }

            return(builder);
        }
        public static void UseMongoDb(this LoggingConfigurationBuilder builder, MongoDatabase database, string logCollectionName)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }
            if (database == null)
            {
                throw new ArgumentNullException("database");
            }
            if (logCollectionName == null)
            {
                throw new ArgumentNullException("logCollectionName");
            }

            UseMongoDbLoggerFactory(database, logCollectionName);
        }
예제 #20
0
        private static void ConfigureLoggingInternal(HostBuilderContext context, IServiceCollection services,
                                                     Action <LoggingConfigurationBuilder> configureLogging, string sectionName)
        {
            var configuration = context.Configuration;

            var configurationSection = configuration.GetSection(sectionName);

            if (configurationSection?.Exists() == false)
            {
                throw new ConfigurationErrorsException($"Configuration section '{sectionName}' is incorrect.");
            }

            var loggerConfiguration = new LoggerConfiguration()
                                      .Enrich.FromLogContext()
                                      .ReadFrom.Configuration(configuration, sectionName);

            var loggerConfigurationBuilder =
                new LoggingConfigurationBuilder(services, loggerConfiguration, configuration.GetSection(sectionName));

            configureLogging?.Invoke(loggerConfigurationBuilder);

            Log.Logger = loggerConfiguration.CreateLogger();
            services.AddLogging(loggerBuilder => loggerBuilder.AddSerilog(Log.Logger, true));
        }
 /// <summary>
 /// Uses Serilog and uses Serilog's static logger factory to create typed loggers
 /// </summary>
 public static void UseSerilog(this LoggingConfigurationBuilder builder)
 {
     CirqusLoggerFactory.Current = new SerilogLoggerFactory();
 }
 /// <summary>
 /// Sets the SDK's logging configuration, using a configuration builder obtained from
 /// <see cref="Components.Logging()"/>.
 /// </summary>
 /// <remarks>
 /// <para>
 /// As a shortcut for disabling logging, you may use <see cref="Components.NoLogging"/> instead.
 /// If all you want to do is to set the basic logging destination, and you do not need to set other
 /// logging properties, you can use <see cref="Logging(ILogAdapter)"/> instead.
 /// </para>
 /// <para>
 /// For more about how logging works in the SDK, see the LaunchDarkly
 /// <a href="https://docs.launchdarkly.com/sdk/features/logging#net-client-side">feature guide</a>.
 /// </para>
 /// <para>
 /// This overwrites any previous options set with <see cref="Logging(LoggingConfigurationBuilder)"/>.
 /// If you want to set multiple options, set them on the same <see cref="LoggingConfigurationBuilder"/>.
 /// </para>
 /// </remarks>
 /// <example>
 ///     var config = Configuration.Builder("my-sdk-key")
 ///         .Logging(Components.Logging().Level(LogLevel.Warn)))
 ///         .Build();
 /// </example>
 /// <param name="loggingConfigurationBuilder">a builder for logging configuration</param>
 /// <returns>the top-level builder</returns>
 /// <seealso cref="Components.Logging()" />
 /// <seealso cref="Components.Logging(ILogAdapter) "/>
 /// <seealso cref="Components.NoLogging" />
 /// <seealso cref="Logging(ILogAdapter)"/>
 public ConfigurationBuilder Logging(LoggingConfigurationBuilder loggingConfigurationBuilder)
 {
     _loggingConfigurationBuilder = loggingConfigurationBuilder;
     return(this);
 }