@@ -43,6 +43,9 @@ public static class LoggerConfigurationMSSqlServerExtensions
43
43
/// Create a database and execute the table creation script found here
44
44
/// https://gist.github.com/mivano/10429656
45
45
/// or use the autoCreateSqlTable option.
46
+ ///
47
+ /// Note: this is the legacy version of the extension method. Please use the new one using SinkOptions instead of separate parameters.
48
+ ///
46
49
/// </summary>
47
50
/// <param name="loggerConfiguration">The logger configuration.</param>
48
51
/// <param name="connectionString">The connection string to the database where to store the events.</param>
@@ -57,8 +60,6 @@ public static class LoggerConfigurationMSSqlServerExtensions
57
60
/// <param name="columnOptionsSection">A config section defining various column settings</param>
58
61
/// <param name="schemaName">Name of the schema for the table to store the data in. The default is 'dbo'.</param>
59
62
/// <param name="logEventFormatter">Supplies custom formatter for the LogEvent column, or null</param>
60
- /// <param name="sinkOptions">Supplies additional settings for the sink</param>
61
- /// <param name="sinkOptionsSection">A config section defining additional settings for the sink</param>
62
63
/// <returns>Logger configuration, allowing configuration to continue.</returns>
63
64
/// <exception cref="ArgumentNullException">A required parameter is null.</exception>
64
65
public static LoggerConfiguration MSSqlServer (
@@ -74,24 +75,61 @@ public static LoggerConfiguration MSSqlServer(
74
75
ColumnOptions columnOptions = null ,
75
76
IConfigurationSection columnOptionsSection = null ,
76
77
string schemaName = "dbo" ,
77
- ITextFormatter logEventFormatter = null ,
78
- SinkOptions sinkOptions = null ,
79
- IConfigurationSection sinkOptionsSection = null ) =>
80
- loggerConfiguration . MSSqlServerInternal (
78
+ ITextFormatter logEventFormatter = null )
79
+ {
80
+ var sinkOptions = new SinkOptions ( tableName , batchPostingLimit , period , autoCreateSqlTable , schemaName ) ;
81
+
82
+ return loggerConfiguration . MSSqlServer (
81
83
connectionString : connectionString ,
82
- tableName : tableName ,
84
+ sinkOptions : sinkOptions ,
83
85
appConfiguration : appConfiguration ,
84
86
restrictedToMinimumLevel : restrictedToMinimumLevel ,
85
- batchPostingLimit : batchPostingLimit ,
86
- period : period ,
87
87
formatProvider : formatProvider ,
88
- autoCreateSqlTable : autoCreateSqlTable ,
89
88
columnOptions : columnOptions ,
90
89
columnOptionsSection : columnOptionsSection ,
91
- schemaName : schemaName ,
92
90
logEventFormatter : logEventFormatter ,
91
+ sinkOptionsSection : null ) ;
92
+ }
93
+
94
+ /// <summary>
95
+ /// Adds a sink that writes log events to a table in a MSSqlServer database.
96
+ /// Create a database and execute the table creation script found here
97
+ /// https://gist.github.com/mivano/10429656
98
+ /// or use the autoCreateSqlTable option.
99
+ /// </summary>
100
+ /// <param name="loggerConfiguration">The logger configuration.</param>
101
+ /// <param name="connectionString">The connection string to the database where to store the events.</param>
102
+ /// <param name="sinkOptions">Supplies additional settings for the sink</param>
103
+ /// <param name="sinkOptionsSection">A config section defining additional settings for the sink</param>
104
+ /// <param name="appConfiguration">Additional application-level configuration. Required if connectionString is a name.</param>
105
+ /// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
106
+ /// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
107
+ /// <param name="columnOptions">An externally-modified group of column settings</param>
108
+ /// <param name="columnOptionsSection">A config section defining various column settings</param>
109
+ /// <param name="logEventFormatter">Supplies custom formatter for the LogEvent column, or null</param>
110
+ /// <returns>Logger configuration, allowing configuration to continue.</returns>
111
+ /// <exception cref="ArgumentNullException">A required parameter is null.</exception>
112
+ public static LoggerConfiguration MSSqlServer (
113
+ this LoggerSinkConfiguration loggerConfiguration ,
114
+ string connectionString ,
115
+ SinkOptions sinkOptions = null ,
116
+ IConfigurationSection sinkOptionsSection = null ,
117
+ IConfiguration appConfiguration = null ,
118
+ LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum ,
119
+ IFormatProvider formatProvider = null ,
120
+ ColumnOptions columnOptions = null ,
121
+ IConfigurationSection columnOptionsSection = null ,
122
+ ITextFormatter logEventFormatter = null ) =>
123
+ loggerConfiguration . MSSqlServerInternal (
124
+ connectionString : connectionString ,
93
125
sinkOptions : sinkOptions ,
94
126
sinkOptionsSection : sinkOptionsSection ,
127
+ appConfiguration : appConfiguration ,
128
+ restrictedToMinimumLevel : restrictedToMinimumLevel ,
129
+ formatProvider : formatProvider ,
130
+ columnOptions : columnOptions ,
131
+ columnOptionsSection : columnOptionsSection ,
132
+ logEventFormatter : logEventFormatter ,
95
133
applySystemConfiguration : new ApplySystemConfiguration ( ) ,
96
134
applyMicrosoftExtensionsConfiguration : new ApplyMicrosoftExtensionsConfiguration ( ) ,
97
135
sinkFactory : new MSSqlServerSinkFactory ( ) ) ;
@@ -100,59 +138,51 @@ public static LoggerConfiguration MSSqlServer(
100
138
internal static LoggerConfiguration MSSqlServerInternal (
101
139
this LoggerSinkConfiguration loggerConfiguration ,
102
140
string connectionString ,
103
- string tableName ,
141
+ SinkOptions sinkOptions = null ,
142
+ IConfigurationSection sinkOptionsSection = null ,
104
143
IConfiguration appConfiguration = null ,
105
144
LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum ,
106
- int batchPostingLimit = MSSqlServerSink . DefaultBatchPostingLimit ,
107
- TimeSpan ? period = null ,
108
145
IFormatProvider formatProvider = null ,
109
- bool autoCreateSqlTable = false ,
110
146
ColumnOptions columnOptions = null ,
111
147
IConfigurationSection columnOptionsSection = null ,
112
- string schemaName = "dbo" ,
113
148
ITextFormatter logEventFormatter = null ,
114
- SinkOptions sinkOptions = null ,
115
- IConfigurationSection sinkOptionsSection = null ,
116
149
IApplySystemConfiguration applySystemConfiguration = null ,
117
150
IApplyMicrosoftExtensionsConfiguration applyMicrosoftExtensionsConfiguration = null ,
118
151
IMSSqlServerSinkFactory sinkFactory = null )
119
152
{
120
153
if ( loggerConfiguration == null )
121
154
throw new ArgumentNullException ( nameof ( loggerConfiguration ) ) ;
122
155
123
- var defaultedPeriod = period ?? MSSqlServerSink . DefaultPeriod ;
124
- var colOpts = columnOptions ?? new ColumnOptions ( ) ;
125
- var connStr = connectionString ;
126
- var sinkOpts = sinkOptions ?? new SinkOptions ( ) ;
156
+ sinkOptions = sinkOptions ?? new SinkOptions ( ) ;
157
+ columnOptions = columnOptions ?? new ColumnOptions ( ) ;
127
158
128
159
var serviceConfigSection = applySystemConfiguration . GetSinkConfigurationSection ( AppConfigSectionName ) ;
129
160
if ( serviceConfigSection != null )
130
161
{
131
- connStr = applySystemConfiguration . GetConnectionString ( connStr ) ;
132
- colOpts = applySystemConfiguration . ConfigureColumnOptions ( serviceConfigSection , colOpts ) ;
133
- // TODO get sink options from config
162
+ connectionString = applySystemConfiguration . GetConnectionString ( connectionString ) ;
163
+ columnOptions = applySystemConfiguration . ConfigureColumnOptions ( serviceConfigSection , columnOptions ) ;
164
+ // TODO get sink options from System.Config
134
165
135
166
if ( appConfiguration != null || columnOptionsSection != null || sinkOptionsSection != null )
136
167
SelfLog . WriteLine ( "Warning: Both System.Configuration (app.config or web.config) and Microsoft.Extensions.Configuration are being applied to the MSSQLServer sink." ) ;
137
168
}
138
169
139
170
if ( appConfiguration != null )
140
171
{
141
- connStr = applyMicrosoftExtensionsConfiguration . GetConnectionString ( connStr , appConfiguration ) ;
172
+ connectionString = applyMicrosoftExtensionsConfiguration . GetConnectionString ( connectionString , appConfiguration ) ;
142
173
}
143
174
144
175
if ( columnOptionsSection != null )
145
176
{
146
- colOpts = applyMicrosoftExtensionsConfiguration . ConfigureColumnOptions ( colOpts , columnOptionsSection ) ;
177
+ columnOptions = applyMicrosoftExtensionsConfiguration . ConfigureColumnOptions ( columnOptions , columnOptionsSection ) ;
147
178
}
148
179
149
180
if ( sinkOptionsSection != null )
150
181
{
151
- sinkOpts = applyMicrosoftExtensionsConfiguration . ConfigureSinkOptions ( sinkOpts , sinkOptionsSection ) ;
182
+ sinkOptions = applyMicrosoftExtensionsConfiguration . ConfigureSinkOptions ( sinkOptions , sinkOptionsSection ) ;
152
183
}
153
184
154
- var sink = sinkFactory . Create ( connStr , tableName , batchPostingLimit , defaultedPeriod , formatProvider ,
155
- autoCreateSqlTable , colOpts , schemaName , logEventFormatter , sinkOpts ) ;
185
+ var sink = sinkFactory . Create ( connectionString , sinkOptions , formatProvider , columnOptions , logEventFormatter ) ;
156
186
157
187
return loggerConfiguration . Sink ( sink , restrictedToMinimumLevel ) ;
158
188
}
0 commit comments