@@ -44,7 +44,7 @@ public static class LoggerConfigurationMSSqlServerExtensions
44
44
/// https://gist.github.com/mivano/10429656
45
45
/// or use the autoCreateSqlTable option.
46
46
///
47
- /// Note: this is the legacy version of the extension method. Please use the new one using SinkOptions instead of separate parameters .
47
+ /// Note: this is the legacy version of the extension method. Please use the new one using SinkOptions instead.
48
48
///
49
49
/// </summary>
50
50
/// <param name="loggerConfiguration">The logger configuration.</param>
@@ -74,9 +74,12 @@ public static LoggerConfiguration MSSqlServer(
74
74
bool autoCreateSqlTable = false ,
75
75
ColumnOptions columnOptions = null ,
76
76
IConfigurationSection columnOptionsSection = null ,
77
- string schemaName = "dbo" ,
77
+ string schemaName = MSSqlServerSink . DefaultSchemaName ,
78
78
ITextFormatter logEventFormatter = null )
79
79
{
80
+ // Do not add new parameters here. This interface is considered legacy and will be deprecated in the future.
81
+ // For adding new input parameters use the SinkOptions class and the method overload that accepts SinkOptions.
82
+
80
83
var sinkOptions = new SinkOptions ( tableName , batchPostingLimit , period , autoCreateSqlTable , schemaName ) ;
81
84
82
85
return loggerConfiguration . MSSqlServer (
@@ -161,7 +164,7 @@ internal static LoggerConfiguration MSSqlServerInternal(
161
164
{
162
165
connectionString = applySystemConfiguration . GetConnectionString ( connectionString ) ;
163
166
columnOptions = applySystemConfiguration . ConfigureColumnOptions ( serviceConfigSection , columnOptions ) ;
164
- // TODO get sink options from System.Config
167
+ sinkOptions = applySystemConfiguration . ConfigureSinkOptions ( serviceConfigSection , sinkOptions ) ;
165
168
166
169
if ( appConfiguration != null || columnOptionsSection != null || sinkOptionsSection != null )
167
170
SelfLog . WriteLine ( "Warning: Both System.Configuration (app.config or web.config) and Microsoft.Extensions.Configuration are being applied to the MSSQLServer sink." ) ;
@@ -189,6 +192,9 @@ internal static LoggerConfiguration MSSqlServerInternal(
189
192
190
193
/// <summary>
191
194
/// Adds a sink that writes log events to a table in a MSSqlServer database.
195
+ ///
196
+ /// Note: this is the legacy version of the extension method. Please use the new one using SinkOptions instead.
197
+ ///
192
198
/// </summary>
193
199
/// <param name="loggerAuditSinkConfiguration">The logger configuration.</param>
194
200
/// <param name="connectionString">The connection string to the database where to store the events.</param>
@@ -201,8 +207,6 @@ internal static LoggerConfiguration MSSqlServerInternal(
201
207
/// <param name="columnOptionsSection">A config section defining various column settings</param>
202
208
/// <param name="schemaName">Name of the schema for the table to store the data in. The default is 'dbo'.</param>
203
209
/// <param name="logEventFormatter">Supplies custom formatter for the LogEvent column, or null</param>
204
- /// <param name="sinkOptions">Supplies additional settings for the sink</param>
205
- /// <param name="sinkOptionsSection">A config section defining additional settings for the sink</param>
206
210
/// <returns>Logger configuration, allowing configuration to continue.</returns>
207
211
/// <exception cref="ArgumentNullException">A required parameter is null.</exception>
208
212
public static LoggerConfiguration MSSqlServer (
@@ -215,23 +219,62 @@ public static LoggerConfiguration MSSqlServer(
215
219
bool autoCreateSqlTable = false ,
216
220
ColumnOptions columnOptions = null ,
217
221
IConfigurationSection columnOptionsSection = null ,
218
- string schemaName = "dbo" ,
219
- ITextFormatter logEventFormatter = null ,
220
- SinkOptions sinkOptions = null ,
221
- IConfigurationSection sinkOptionsSection = null ) =>
222
- loggerAuditSinkConfiguration . MSSqlServerInternal (
222
+ string schemaName = MSSqlServerSink . DefaultSchemaName ,
223
+ ITextFormatter logEventFormatter = null )
224
+ {
225
+ // Do not add new parameters here. This interface is considered legacy and will be deprecated in the future.
226
+ // For adding new input parameters use the SinkOptions class and the method overload that accepts SinkOptions.
227
+
228
+ var sinkOptions = new SinkOptions ( tableName , null , null , autoCreateSqlTable , schemaName ) ;
229
+
230
+ return loggerAuditSinkConfiguration . MSSqlServer (
223
231
connectionString : connectionString ,
224
- tableName : tableName ,
232
+ sinkOptions : sinkOptions ,
225
233
appConfiguration : appConfiguration ,
226
234
restrictedToMinimumLevel : restrictedToMinimumLevel ,
227
235
formatProvider : formatProvider ,
228
- autoCreateSqlTable : autoCreateSqlTable ,
229
236
columnOptions : columnOptions ,
230
237
columnOptionsSection : columnOptionsSection ,
231
- schemaName : schemaName ,
232
238
logEventFormatter : logEventFormatter ,
239
+ sinkOptionsSection : null ) ;
240
+ }
241
+
242
+ /// <summary>
243
+ /// Adds a sink that writes log events to a table in a MSSqlServer database.
244
+ /// </summary>
245
+ /// <param name="loggerAuditSinkConfiguration">The logger configuration.</param>
246
+ /// <param name="connectionString">The connection string to the database where to store the events.</param>
247
+ /// <param name="sinkOptions">Supplies additional settings for the sink</param>
248
+ /// <param name="sinkOptionsSection">A config section defining additional settings for the sink</param>
249
+ /// <param name="appConfiguration">Additional application-level configuration. Required if connectionString is a name.</param>
250
+ /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
251
+ /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
252
+ /// <param name="columnOptions">An externally-modified group of column settings</param>
253
+ /// <param name="columnOptionsSection">A config section defining various column settings</param>
254
+ /// <param name="logEventFormatter">Supplies custom formatter for the LogEvent column, or null</param>
255
+ /// <returns>Logger configuration, allowing configuration to continue.</returns>
256
+ /// <exception cref="ArgumentNullException">A required parameter is null.</exception>
257
+ public static LoggerConfiguration MSSqlServer (
258
+ this LoggerAuditSinkConfiguration loggerAuditSinkConfiguration ,
259
+ string connectionString ,
260
+ SinkOptions sinkOptions = null ,
261
+ IConfigurationSection sinkOptionsSection = null ,
262
+ IConfiguration appConfiguration = null ,
263
+ LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum ,
264
+ IFormatProvider formatProvider = null ,
265
+ ColumnOptions columnOptions = null ,
266
+ IConfigurationSection columnOptionsSection = null ,
267
+ ITextFormatter logEventFormatter = null ) =>
268
+ loggerAuditSinkConfiguration . MSSqlServerInternal (
269
+ connectionString : connectionString ,
233
270
sinkOptions : sinkOptions ,
234
271
sinkOptionsSection : sinkOptionsSection ,
272
+ appConfiguration : appConfiguration ,
273
+ restrictedToMinimumLevel : restrictedToMinimumLevel ,
274
+ formatProvider : formatProvider ,
275
+ columnOptions : columnOptions ,
276
+ columnOptionsSection : columnOptionsSection ,
277
+ logEventFormatter : logEventFormatter ,
235
278
applySystemConfiguration : new ApplySystemConfiguration ( ) ,
236
279
applyMicrosoftExtensionsConfiguration : new ApplyMicrosoftExtensionsConfiguration ( ) ,
237
280
auditSinkFactory : new MSSqlServerAuditSinkFactory ( ) ) ;
@@ -240,56 +283,51 @@ public static LoggerConfiguration MSSqlServer(
240
283
internal static LoggerConfiguration MSSqlServerInternal (
241
284
this LoggerAuditSinkConfiguration loggerAuditSinkConfiguration ,
242
285
string connectionString ,
243
- string tableName ,
286
+ SinkOptions sinkOptions = null ,
287
+ IConfigurationSection sinkOptionsSection = null ,
244
288
IConfiguration appConfiguration = null ,
245
289
LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum ,
246
290
IFormatProvider formatProvider = null ,
247
- bool autoCreateSqlTable = false ,
248
291
ColumnOptions columnOptions = null ,
249
292
IConfigurationSection columnOptionsSection = null ,
250
- string schemaName = "dbo" ,
251
293
ITextFormatter logEventFormatter = null ,
252
- SinkOptions sinkOptions = null ,
253
- IConfigurationSection sinkOptionsSection = null ,
254
294
IApplySystemConfiguration applySystemConfiguration = null ,
255
295
IApplyMicrosoftExtensionsConfiguration applyMicrosoftExtensionsConfiguration = null ,
256
296
IMSSqlServerAuditSinkFactory auditSinkFactory = null )
257
297
{
258
298
if ( loggerAuditSinkConfiguration == null )
259
299
throw new ArgumentNullException ( nameof ( loggerAuditSinkConfiguration ) ) ;
260
300
261
- var colOpts = columnOptions ?? new ColumnOptions ( ) ;
262
- var connStr = connectionString ;
263
- var sinkOpts = sinkOptions ?? new SinkOptions ( ) ;
301
+ sinkOptions = sinkOptions ?? new SinkOptions ( ) ;
302
+ columnOptions = columnOptions ?? new ColumnOptions ( ) ;
264
303
265
304
var serviceConfigSection = applySystemConfiguration . GetSinkConfigurationSection ( AppConfigSectionName ) ;
266
305
if ( serviceConfigSection != null )
267
306
{
268
- connStr = applySystemConfiguration . GetConnectionString ( connStr ) ;
269
- colOpts = applySystemConfiguration . ConfigureColumnOptions ( serviceConfigSection , colOpts ) ;
270
- // TODO get sink options from config
307
+ connectionString = applySystemConfiguration . GetConnectionString ( connectionString ) ;
308
+ columnOptions = applySystemConfiguration . ConfigureColumnOptions ( serviceConfigSection , columnOptions ) ;
309
+ sinkOptions = applySystemConfiguration . ConfigureSinkOptions ( serviceConfigSection , sinkOptions ) ;
271
310
272
311
if ( appConfiguration != null || columnOptionsSection != null || sinkOptionsSection != null )
273
312
SelfLog . WriteLine ( "Warning: Both System.Configuration (app.config or web.config) and Microsoft.Extensions.Configuration are being applied to the MSSQLServer sink." ) ;
274
313
}
275
314
276
315
if ( appConfiguration != null )
277
316
{
278
- connStr = applyMicrosoftExtensionsConfiguration . GetConnectionString ( connStr , appConfiguration ) ;
317
+ connectionString = applyMicrosoftExtensionsConfiguration . GetConnectionString ( connectionString , appConfiguration ) ;
279
318
}
280
319
281
320
if ( columnOptionsSection != null )
282
321
{
283
- colOpts = applyMicrosoftExtensionsConfiguration . ConfigureColumnOptions ( colOpts , columnOptionsSection ) ;
322
+ columnOptions = applyMicrosoftExtensionsConfiguration . ConfigureColumnOptions ( columnOptions , columnOptionsSection ) ;
284
323
}
285
324
286
325
if ( sinkOptionsSection != null )
287
326
{
288
- sinkOpts = applyMicrosoftExtensionsConfiguration . ConfigureSinkOptions ( sinkOpts , sinkOptionsSection ) ;
327
+ sinkOptions = applyMicrosoftExtensionsConfiguration . ConfigureSinkOptions ( sinkOptions , sinkOptionsSection ) ;
289
328
}
290
329
291
- var auditSink = auditSinkFactory . Create ( connStr , tableName , formatProvider , autoCreateSqlTable ,
292
- colOpts , schemaName , logEventFormatter , sinkOpts ) ;
330
+ var auditSink = auditSinkFactory . Create ( connectionString , sinkOptions , formatProvider , columnOptions , logEventFormatter ) ;
293
331
294
332
return loggerAuditSinkConfiguration . Sink ( auditSink , restrictedToMinimumLevel ) ;
295
333
}
0 commit comments