2020using Serilog . Formatting ;
2121using Serilog . Sinks . MSSqlServer ;
2222using Serilog . Sinks . MSSqlServer . Configuration . Factories ;
23- using Serilog . Sinks . MSSqlServer . Sinks . MSSqlServer . Options ;
2423
2524// The "Hybrid" configuration system supports both Microsoft.Extensions.Configuration and System.Configuration.
2625// This is necessary because .NET Framework 4.6.1+ and .NET Core 2.0+ apps support both approaches, whereas the
@@ -44,7 +43,7 @@ public static class LoggerConfigurationMSSqlServerExtensions
4443 /// https://gist.github.com/mivano/10429656
4544 /// or use the autoCreateSqlTable option.
4645 ///
47- /// Note: this is the legacy version of the extension method. Please use the new one using SinkOptions instead.
46+ /// Note: this is the legacy version of the extension method. Please use the new one using MSSqlServerSinkOptions instead.
4847 ///
4948 /// </summary>
5049 /// <param name="loggerConfiguration">The logger configuration.</param>
@@ -62,7 +61,7 @@ public static class LoggerConfigurationMSSqlServerExtensions
6261 /// <param name="logEventFormatter">Supplies custom formatter for the LogEvent column, or null</param>
6362 /// <returns>Logger configuration, allowing configuration to continue.</returns>
6463 /// <exception cref="ArgumentNullException">A required parameter is null.</exception>
65- [ Obsolete ( "Use the new interface accepting a SinkOptions parameter instead. This will be removed in a future release." , error : false ) ]
64+ [ Obsolete ( "Use the new interface accepting a MSSqlServerSinkOptions parameter instead. This will be removed in a future release." , error : false ) ]
6665 public static LoggerConfiguration MSSqlServer (
6766 this LoggerSinkConfiguration loggerConfiguration ,
6867 string connectionString ,
@@ -79,9 +78,9 @@ public static LoggerConfiguration MSSqlServer(
7978 ITextFormatter logEventFormatter = null )
8079 {
8180 // Do not add new parameters here. This interface is considered legacy and will be deprecated in the future.
82- // For adding new input parameters use the SinkOptions class and the method overload that accepts SinkOptions .
81+ // For adding new input parameters use the MSSqlServerSinkOptions class and the method overload that accepts MSSqlServerSinkOptions .
8382
84- var sinkOptions = new SinkOptions ( tableName , batchPostingLimit , period , autoCreateSqlTable , schemaName ) ;
83+ var sinkOptions = new MSSqlServerSinkOptions ( tableName , batchPostingLimit , period , autoCreateSqlTable , schemaName ) ;
8584
8685 return loggerConfiguration . MSSqlServer (
8786 connectionString : connectionString ,
@@ -116,7 +115,7 @@ public static LoggerConfiguration MSSqlServer(
116115 public static LoggerConfiguration MSSqlServer (
117116 this LoggerSinkConfiguration loggerConfiguration ,
118117 string connectionString ,
119- SinkOptions sinkOptions = null ,
118+ MSSqlServerSinkOptions sinkOptions = null ,
120119 IConfigurationSection sinkOptionsSection = null ,
121120 IConfiguration appConfiguration = null ,
122121 LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum ,
@@ -136,23 +135,25 @@ public static LoggerConfiguration MSSqlServer(
136135 logEventFormatter : logEventFormatter ,
137136 applySystemConfiguration : new ApplySystemConfiguration ( ) ,
138137 applyMicrosoftExtensionsConfiguration : new ApplyMicrosoftExtensionsConfiguration ( ) ,
139- sinkFactory : new MSSqlServerSinkFactory ( ) ) ;
138+ sinkFactory : new MSSqlServerSinkFactory ( ) ,
139+ batchingSinkFactory : new PeriodicBatchingSinkFactory ( ) ) ;
140140
141141 // Internal overload with parameters used by tests to override the config section and inject mocks
142142 internal static LoggerConfiguration MSSqlServerInternal (
143143 this LoggerSinkConfiguration loggerConfiguration ,
144144 string connectionString ,
145- SinkOptions sinkOptions = null ,
146- IConfigurationSection sinkOptionsSection = null ,
147- IConfiguration appConfiguration = null ,
148- LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum ,
149- IFormatProvider formatProvider = null ,
150- ColumnOptions columnOptions = null ,
151- IConfigurationSection columnOptionsSection = null ,
152- ITextFormatter logEventFormatter = null ,
153- IApplySystemConfiguration applySystemConfiguration = null ,
154- IApplyMicrosoftExtensionsConfiguration applyMicrosoftExtensionsConfiguration = null ,
155- IMSSqlServerSinkFactory sinkFactory = null )
145+ MSSqlServerSinkOptions sinkOptions ,
146+ IConfigurationSection sinkOptionsSection ,
147+ IConfiguration appConfiguration ,
148+ LogEventLevel restrictedToMinimumLevel ,
149+ IFormatProvider formatProvider ,
150+ ColumnOptions columnOptions ,
151+ IConfigurationSection columnOptionsSection ,
152+ ITextFormatter logEventFormatter ,
153+ IApplySystemConfiguration applySystemConfiguration ,
154+ IApplyMicrosoftExtensionsConfiguration applyMicrosoftExtensionsConfiguration ,
155+ IMSSqlServerSinkFactory sinkFactory ,
156+ IPeriodicBatchingSinkFactory batchingSinkFactory )
156157 {
157158 if ( loggerConfiguration == null )
158159 throw new ArgumentNullException ( nameof ( loggerConfiguration ) ) ;
@@ -162,13 +163,15 @@ internal static LoggerConfiguration MSSqlServerInternal(
162163
163164 var sink = sinkFactory . Create ( connectionString , sinkOptions , formatProvider , columnOptions , logEventFormatter ) ;
164165
165- return loggerConfiguration . Sink ( sink , restrictedToMinimumLevel ) ;
166+ var periodicBatchingSink = batchingSinkFactory . Create ( sink , sinkOptions ) ;
167+
168+ return loggerConfiguration . Sink ( periodicBatchingSink , restrictedToMinimumLevel ) ;
166169 }
167170
168171 /// <summary>
169172 /// Adds a sink that writes log events to a table in a MSSqlServer database.
170173 ///
171- /// Note: this is the legacy version of the extension method. Please use the new one using SinkOptions instead.
174+ /// Note: this is the legacy version of the extension method. Please use the new one using MSSqlServerSinkOptions instead.
172175 ///
173176 /// </summary>
174177 /// <param name="loggerAuditSinkConfiguration">The logger configuration.</param>
@@ -184,7 +187,7 @@ internal static LoggerConfiguration MSSqlServerInternal(
184187 /// <param name="logEventFormatter">Supplies custom formatter for the LogEvent column, or null</param>
185188 /// <returns>Logger configuration, allowing configuration to continue.</returns>
186189 /// <exception cref="ArgumentNullException">A required parameter is null.</exception>
187- [ Obsolete ( "Use the new interface accepting a SinkOptions parameter instead. This will be removed in a future release." , error : false ) ]
190+ [ Obsolete ( "Use the new interface accepting a MSSqlServerSinkOptions parameter instead. This will be removed in a future release." , error : false ) ]
188191 public static LoggerConfiguration MSSqlServer (
189192 this LoggerAuditSinkConfiguration loggerAuditSinkConfiguration ,
190193 string connectionString ,
@@ -199,9 +202,9 @@ public static LoggerConfiguration MSSqlServer(
199202 ITextFormatter logEventFormatter = null )
200203 {
201204 // Do not add new parameters here. This interface is considered legacy and will be deprecated in the future.
202- // For adding new input parameters use the SinkOptions class and the method overload that accepts SinkOptions .
205+ // For adding new input parameters use the MSSqlServerSinkOptions class and the method overload that accepts MSSqlServerSinkOptions .
203206
204- var sinkOptions = new SinkOptions ( tableName , null , null , autoCreateSqlTable , schemaName ) ;
207+ var sinkOptions = new MSSqlServerSinkOptions ( tableName , null , null , autoCreateSqlTable , schemaName ) ;
205208
206209 return loggerAuditSinkConfiguration . MSSqlServer (
207210 connectionString : connectionString ,
@@ -233,7 +236,7 @@ public static LoggerConfiguration MSSqlServer(
233236 public static LoggerConfiguration MSSqlServer (
234237 this LoggerAuditSinkConfiguration loggerAuditSinkConfiguration ,
235238 string connectionString ,
236- SinkOptions sinkOptions = null ,
239+ MSSqlServerSinkOptions sinkOptions = null ,
237240 IConfigurationSection sinkOptionsSection = null ,
238241 IConfiguration appConfiguration = null ,
239242 LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum ,
@@ -259,17 +262,17 @@ public static LoggerConfiguration MSSqlServer(
259262 internal static LoggerConfiguration MSSqlServerInternal (
260263 this LoggerAuditSinkConfiguration loggerAuditSinkConfiguration ,
261264 string connectionString ,
262- SinkOptions sinkOptions = null ,
263- IConfigurationSection sinkOptionsSection = null ,
264- IConfiguration appConfiguration = null ,
265- LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum ,
266- IFormatProvider formatProvider = null ,
267- ColumnOptions columnOptions = null ,
268- IConfigurationSection columnOptionsSection = null ,
269- ITextFormatter logEventFormatter = null ,
270- IApplySystemConfiguration applySystemConfiguration = null ,
271- IApplyMicrosoftExtensionsConfiguration applyMicrosoftExtensionsConfiguration = null ,
272- IMSSqlServerAuditSinkFactory auditSinkFactory = null )
265+ MSSqlServerSinkOptions sinkOptions ,
266+ IConfigurationSection sinkOptionsSection ,
267+ IConfiguration appConfiguration ,
268+ LogEventLevel restrictedToMinimumLevel ,
269+ IFormatProvider formatProvider ,
270+ ColumnOptions columnOptions ,
271+ IConfigurationSection columnOptionsSection ,
272+ ITextFormatter logEventFormatter ,
273+ IApplySystemConfiguration applySystemConfiguration ,
274+ IApplyMicrosoftExtensionsConfiguration applyMicrosoftExtensionsConfiguration ,
275+ IMSSqlServerAuditSinkFactory auditSinkFactory )
273276 {
274277 if ( loggerAuditSinkConfiguration == null )
275278 throw new ArgumentNullException ( nameof ( loggerAuditSinkConfiguration ) ) ;
@@ -284,15 +287,15 @@ internal static LoggerConfiguration MSSqlServerInternal(
284287
285288 private static void ReadConfiguration (
286289 ref string connectionString ,
287- ref SinkOptions sinkOptions ,
290+ ref MSSqlServerSinkOptions sinkOptions ,
288291 IConfigurationSection sinkOptionsSection ,
289292 IConfiguration appConfiguration ,
290293 ref ColumnOptions columnOptions ,
291294 IConfigurationSection columnOptionsSection ,
292295 IApplySystemConfiguration applySystemConfiguration ,
293296 IApplyMicrosoftExtensionsConfiguration applyMicrosoftExtensionsConfiguration )
294297 {
295- sinkOptions = sinkOptions ?? new SinkOptions ( ) ;
298+ sinkOptions = sinkOptions ?? new MSSqlServerSinkOptions ( ) ;
296299 columnOptions = columnOptions ?? new ColumnOptions ( ) ;
297300
298301 var serviceConfigSection = applySystemConfiguration . GetSinkConfigurationSection ( AppConfigSectionName ) ;
0 commit comments