/// <summary>
        /// Adds a sink that writes log events to a table in a MSSqlServer database.
        /// Create a database and execute the table creation script found here
        /// https://gist.github.com/mivano/10429656
        /// or use the autoCreateSqlTable option.
        /// </summary>
        /// <param name="loggerConfiguration">The logger configuration.</param>
        /// <param name="connectionString">The connection string to the database where to store the events.</param>
        /// <param name="sinkOptions">Supplies additional settings for the sink</param>
        /// <param name="sinkOptionsSection">A config section defining additional settings for the sink</param>
        /// <param name="appConfiguration">Additional application-level configuration. Required if connectionString is a name.</param>
        /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
        /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
        /// <param name="columnOptions">An externally-modified group of column settings</param>
        /// <param name="columnOptionsSection">A config section defining various column settings</param>
        /// <param name="logEventFormatter">Supplies custom formatter for the LogEvent column, or null</param>
        /// <returns>Logger configuration, allowing configuration to continue.</returns>
        /// <exception cref="ArgumentNullException">A required parameter is null.</exception>
        public static LoggerConfiguration MSSqlServer(
            this LoggerSinkConfiguration loggerConfiguration,
            string connectionString,
            MSSqlServerSinkOptions sinkOptions       = null,
            IConfigurationSection sinkOptionsSection = null,
            IConfiguration appConfiguration          = null,
            LogEventLevel restrictedToMinimumLevel   = LevelAlias.Minimum,
            IFormatProvider formatProvider           = null,
            ColumnOptions columnOptions = null,
            IConfigurationSection columnOptionsSection = null,
            ITextFormatter logEventFormatter           = null)
        {
            if (loggerConfiguration == null)
            {
                throw new ArgumentNullException(nameof(loggerConfiguration));
            }

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

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

            IPeriodicBatchingSinkFactory periodicBatchingSinkFactory = new PeriodicBatchingSinkFactory();
            var periodicBatchingSink = periodicBatchingSinkFactory.Create(sink, sinkOptions);

            return(loggerConfiguration.Sink(periodicBatchingSink, restrictedToMinimumLevel));
        }
Ejemplo n.º 2
0
        public void PeriodicBatchingSinkFactoryCreateReturnsInstance()
        {
            // Arrange
            var sinkMock = new Mock <IBatchedLogEventSink>();
            var sut      = new PeriodicBatchingSinkFactory();

            // Act
            var result = sut.Create(sinkMock.Object, new MSSqlServerSinkOptions());

            // Assert
            Assert.IsType <PeriodicBatchingSink>(result);
        }