// 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));
        }
        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);
            }
        }