// Internal overload with parameters used by tests to override the config section and inject mocks
        internal static LoggerConfiguration MSSqlServerInternal(
            this LoggerAuditSinkConfiguration loggerAuditSinkConfiguration,
            string connectionString,
            MSSqlServerSinkOptions sinkOptions,
            IConfigurationSection sinkOptionsSection,
            IConfiguration appConfiguration,
            LogEventLevel restrictedToMinimumLevel,
            IFormatProvider formatProvider,
            ColumnOptions columnOptions,
            IConfigurationSection columnOptionsSection,
            ITextFormatter logEventFormatter,
            IApplySystemConfiguration applySystemConfiguration,
            IApplyMicrosoftExtensionsConfiguration applyMicrosoftExtensionsConfiguration,
            IMSSqlServerAuditSinkFactory auditSinkFactory)
        {
            if (loggerAuditSinkConfiguration == null)
            {
                throw new ArgumentNullException(nameof(loggerAuditSinkConfiguration));
            }

            ReadConfiguration(ref connectionString, ref sinkOptions, sinkOptionsSection, appConfiguration,
                              ref columnOptions, columnOptionsSection, applySystemConfiguration, applyMicrosoftExtensionsConfiguration);

            var auditSink = auditSinkFactory.Create(connectionString, sinkOptions, formatProvider, columnOptions, logEventFormatter);

            return(loggerAuditSinkConfiguration.Sink(auditSink, restrictedToMinimumLevel));
        }
        // Internal overload with parameters used by tests to override the config section and inject mocks
        internal static LoggerConfiguration MSSqlServerInternal(
            this LoggerSinkConfiguration loggerConfiguration,
            string configSectionName,
            string connectionString,
            MSSqlServerSinkOptions sinkOptions,
            LogEventLevel restrictedToMinimumLevel,
            IFormatProvider formatProvider,
            ColumnOptions columnOptions,
            ITextFormatter logEventFormatter,
            IApplySystemConfiguration applySystemConfiguration,
            IMSSqlServerSinkFactory sinkFactory,
            IPeriodicBatchingSinkFactory batchingSinkFactory)
        {
            if (loggerConfiguration == null)
            {
                throw new ArgumentNullException(nameof(loggerConfiguration));
            }

            ReadConfiguration(configSectionName, ref connectionString, ref sinkOptions, ref columnOptions, applySystemConfiguration);

            var sink = sinkFactory.Create(connectionString, sinkOptions, formatProvider, columnOptions, logEventFormatter);

            var periodicBatchingSink = batchingSinkFactory.Create(sink, sinkOptions);

            return(loggerConfiguration.Sink(periodicBatchingSink, restrictedToMinimumLevel));
        }
        private static void ReadConfiguration(
            ref string connectionString,
            ref MSSqlServerSinkOptions sinkOptions,
            IConfigurationSection sinkOptionsSection,
            IConfiguration appConfiguration,
            ref ColumnOptions columnOptions,
            IConfigurationSection columnOptionsSection,
            IApplySystemConfiguration applySystemConfiguration,
            IApplyMicrosoftExtensionsConfiguration applyMicrosoftExtensionsConfiguration)
        {
            sinkOptions   = sinkOptions ?? new MSSqlServerSinkOptions();
            columnOptions = columnOptions ?? new ColumnOptions();

            var serviceConfigSection = applySystemConfiguration.GetSinkConfigurationSection(AppConfigSectionName);

            if (serviceConfigSection != null)
            {
                connectionString = applySystemConfiguration.GetConnectionString(connectionString);
                columnOptions    = applySystemConfiguration.ConfigureColumnOptions(serviceConfigSection, columnOptions);
                sinkOptions      = applySystemConfiguration.ConfigureSinkOptions(serviceConfigSection, sinkOptions);

                if (appConfiguration != null || columnOptionsSection != null || sinkOptionsSection != null)
                {
                    SelfLog.WriteLine("Warning: Both System.Configuration (app.config or web.config) and Microsoft.Extensions.Configuration are being applied to the MSSQLServer sink.");
                }
            }

            if (appConfiguration != null)
            {
                connectionString = applyMicrosoftExtensionsConfiguration.GetConnectionString(connectionString, appConfiguration);
            }

            if (columnOptionsSection != null)
            {
                columnOptions = applyMicrosoftExtensionsConfiguration.ConfigureColumnOptions(columnOptions, columnOptionsSection);
            }

            if (sinkOptionsSection != null)
            {
                sinkOptions = applyMicrosoftExtensionsConfiguration.ConfigureSinkOptions(sinkOptions, sinkOptionsSection);
            }
        }
Пример #4
0
        private static void ReadConfiguration(
            string configSectionName,
            ref string connectionString,
            ref SinkOptions sinkOptions,
            ref ColumnOptions columnOptions,
            IApplySystemConfiguration applySystemConfiguration)
        {
            sinkOptions   = sinkOptions ?? new SinkOptions();
            columnOptions = columnOptions ?? new ColumnOptions();

            var serviceConfigSection = applySystemConfiguration.GetSinkConfigurationSection(configSectionName);

            if (serviceConfigSection != null)
            {
                columnOptions = applySystemConfiguration.ConfigureColumnOptions(serviceConfigSection, columnOptions);
                sinkOptions   = applySystemConfiguration.ConfigureSinkOptions(serviceConfigSection, sinkOptions);
            }

            connectionString = applySystemConfiguration.GetConnectionString(connectionString);
        }
Пример #5
0
        // Internal overload with parameters used by tests to override the config section and inject mocks
        internal static LoggerConfiguration MSSqlServerInternal(
            this LoggerAuditSinkConfiguration loggerAuditSinkConfiguration,
            string configSectionName,
            string connectionString,
            SinkOptions sinkOptions = null,
            LogEventLevel restrictedToMinimumLevel             = LevelAlias.Minimum,
            IFormatProvider formatProvider                     = null,
            ColumnOptions columnOptions                        = null,
            ITextFormatter logEventFormatter                   = null,
            IApplySystemConfiguration applySystemConfiguration = null,
            IMSSqlServerAuditSinkFactory auditSinkFactory      = null)
        {
            if (loggerAuditSinkConfiguration == null)
            {
                throw new ArgumentNullException(nameof(loggerAuditSinkConfiguration));
            }

            ReadConfiguration(configSectionName, ref connectionString, ref sinkOptions, ref columnOptions, applySystemConfiguration);

            var auditSink = auditSinkFactory.Create(connectionString, sinkOptions, formatProvider, columnOptions, logEventFormatter);

            return(loggerAuditSinkConfiguration.Sink(auditSink, restrictedToMinimumLevel));
        }