20
20
using Serilog . Formatting ;
21
21
using Serilog . Sinks . MSSqlServer ;
22
22
using Serilog . Sinks . MSSqlServer . Configuration . Factories ;
23
- using Serilog . Sinks . MSSqlServer . Sinks . MSSqlServer . Options ;
24
23
25
24
// The "Hybrid" configuration system supports both Microsoft.Extensions.Configuration and System.Configuration.
26
25
// 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
44
43
/// https://gist.github.com/mivano/10429656
45
44
/// or use the autoCreateSqlTable option.
46
45
///
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.
48
47
///
49
48
/// </summary>
50
49
/// <param name="loggerConfiguration">The logger configuration.</param>
@@ -62,7 +61,7 @@ public static class LoggerConfigurationMSSqlServerExtensions
62
61
/// <param name="logEventFormatter">Supplies custom formatter for the LogEvent column, or null</param>
63
62
/// <returns>Logger configuration, allowing configuration to continue.</returns>
64
63
/// <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 ) ]
66
65
public static LoggerConfiguration MSSqlServer (
67
66
this LoggerSinkConfiguration loggerConfiguration ,
68
67
string connectionString ,
@@ -79,9 +78,9 @@ public static LoggerConfiguration MSSqlServer(
79
78
ITextFormatter logEventFormatter = null )
80
79
{
81
80
// 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 .
83
82
84
- var sinkOptions = new SinkOptions ( tableName , batchPostingLimit , period , autoCreateSqlTable , schemaName ) ;
83
+ var sinkOptions = new MSSqlServerSinkOptions ( tableName , batchPostingLimit , period , autoCreateSqlTable , schemaName ) ;
85
84
86
85
return loggerConfiguration . MSSqlServer (
87
86
connectionString : connectionString ,
@@ -116,7 +115,7 @@ public static LoggerConfiguration MSSqlServer(
116
115
public static LoggerConfiguration MSSqlServer (
117
116
this LoggerSinkConfiguration loggerConfiguration ,
118
117
string connectionString ,
119
- SinkOptions sinkOptions = null ,
118
+ MSSqlServerSinkOptions sinkOptions = null ,
120
119
IConfigurationSection sinkOptionsSection = null ,
121
120
IConfiguration appConfiguration = null ,
122
121
LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum ,
@@ -136,23 +135,25 @@ public static LoggerConfiguration MSSqlServer(
136
135
logEventFormatter : logEventFormatter ,
137
136
applySystemConfiguration : new ApplySystemConfiguration ( ) ,
138
137
applyMicrosoftExtensionsConfiguration : new ApplyMicrosoftExtensionsConfiguration ( ) ,
139
- sinkFactory : new MSSqlServerSinkFactory ( ) ) ;
138
+ sinkFactory : new MSSqlServerSinkFactory ( ) ,
139
+ batchingSinkFactory : new PeriodicBatchingSinkFactory ( ) ) ;
140
140
141
141
// Internal overload with parameters used by tests to override the config section and inject mocks
142
142
internal static LoggerConfiguration MSSqlServerInternal (
143
143
this LoggerSinkConfiguration loggerConfiguration ,
144
144
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 )
156
157
{
157
158
if ( loggerConfiguration == null )
158
159
throw new ArgumentNullException ( nameof ( loggerConfiguration ) ) ;
@@ -162,13 +163,15 @@ internal static LoggerConfiguration MSSqlServerInternal(
162
163
163
164
var sink = sinkFactory . Create ( connectionString , sinkOptions , formatProvider , columnOptions , logEventFormatter ) ;
164
165
165
- return loggerConfiguration . Sink ( sink , restrictedToMinimumLevel ) ;
166
+ var periodicBatchingSink = batchingSinkFactory . Create ( sink , sinkOptions ) ;
167
+
168
+ return loggerConfiguration . Sink ( periodicBatchingSink , restrictedToMinimumLevel ) ;
166
169
}
167
170
168
171
/// <summary>
169
172
/// Adds a sink that writes log events to a table in a MSSqlServer database.
170
173
///
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.
172
175
///
173
176
/// </summary>
174
177
/// <param name="loggerAuditSinkConfiguration">The logger configuration.</param>
@@ -184,7 +187,7 @@ internal static LoggerConfiguration MSSqlServerInternal(
184
187
/// <param name="logEventFormatter">Supplies custom formatter for the LogEvent column, or null</param>
185
188
/// <returns>Logger configuration, allowing configuration to continue.</returns>
186
189
/// <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 ) ]
188
191
public static LoggerConfiguration MSSqlServer (
189
192
this LoggerAuditSinkConfiguration loggerAuditSinkConfiguration ,
190
193
string connectionString ,
@@ -199,9 +202,9 @@ public static LoggerConfiguration MSSqlServer(
199
202
ITextFormatter logEventFormatter = null )
200
203
{
201
204
// 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 .
203
206
204
- var sinkOptions = new SinkOptions ( tableName , null , null , autoCreateSqlTable , schemaName ) ;
207
+ var sinkOptions = new MSSqlServerSinkOptions ( tableName , null , null , autoCreateSqlTable , schemaName ) ;
205
208
206
209
return loggerAuditSinkConfiguration . MSSqlServer (
207
210
connectionString : connectionString ,
@@ -233,7 +236,7 @@ public static LoggerConfiguration MSSqlServer(
233
236
public static LoggerConfiguration MSSqlServer (
234
237
this LoggerAuditSinkConfiguration loggerAuditSinkConfiguration ,
235
238
string connectionString ,
236
- SinkOptions sinkOptions = null ,
239
+ MSSqlServerSinkOptions sinkOptions = null ,
237
240
IConfigurationSection sinkOptionsSection = null ,
238
241
IConfiguration appConfiguration = null ,
239
242
LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum ,
@@ -259,17 +262,17 @@ public static LoggerConfiguration MSSqlServer(
259
262
internal static LoggerConfiguration MSSqlServerInternal (
260
263
this LoggerAuditSinkConfiguration loggerAuditSinkConfiguration ,
261
264
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 )
273
276
{
274
277
if ( loggerAuditSinkConfiguration == null )
275
278
throw new ArgumentNullException ( nameof ( loggerAuditSinkConfiguration ) ) ;
@@ -284,15 +287,15 @@ internal static LoggerConfiguration MSSqlServerInternal(
284
287
285
288
private static void ReadConfiguration (
286
289
ref string connectionString ,
287
- ref SinkOptions sinkOptions ,
290
+ ref MSSqlServerSinkOptions sinkOptions ,
288
291
IConfigurationSection sinkOptionsSection ,
289
292
IConfiguration appConfiguration ,
290
293
ref ColumnOptions columnOptions ,
291
294
IConfigurationSection columnOptionsSection ,
292
295
IApplySystemConfiguration applySystemConfiguration ,
293
296
IApplyMicrosoftExtensionsConfiguration applyMicrosoftExtensionsConfiguration )
294
297
{
295
- sinkOptions = sinkOptions ?? new SinkOptions ( ) ;
298
+ sinkOptions = sinkOptions ?? new MSSqlServerSinkOptions ( ) ;
296
299
columnOptions = columnOptions ?? new ColumnOptions ( ) ;
297
300
298
301
var serviceConfigSection = applySystemConfiguration . GetSinkConfigurationSection ( AppConfigSectionName ) ;
0 commit comments