@@ -90,7 +90,7 @@ public MSSqlServerSink(
9090 if ( _columnOptions . AdditionalDataColumns != null )
9191 _additionalDataColumnNames = new HashSet < string > ( _columnOptions . AdditionalDataColumns . Select ( c => c . ColumnName ) , StringComparer . OrdinalIgnoreCase ) ;
9292
93- if ( _columnOptions . Store . Contains ( StandardColumn . LogEvent ) )
93+ if ( _columnOptions . Store . ContainsKey ( StandardColumn . LogEvent ) )
9494 _jsonFormatter = new JsonFormatter ( formatProvider : formatProvider ) ;
9595
9696 // Prepare the data table
@@ -168,90 +168,43 @@ DataTable CreateDataTable()
168168 } ;
169169 eventsTable . Columns . Add ( id ) ;
170170
171- if ( _columnOptions . Store . Contains ( StandardColumn . Message ) )
171+ foreach ( var standardColumn in _columnOptions . Store )
172172 {
173- var message = new DataColumn
173+ switch ( standardColumn . Key )
174174 {
175- DataType = typeof ( string ) ,
176- MaxLength = - 1 ,
177- ColumnName = "Message"
178- } ;
179- eventsTable . Columns . Add ( message ) ;
180- }
181-
182- if ( _columnOptions . Store . Contains ( StandardColumn . MessageTemplate ) )
183- {
184- var messageTemplate = new DataColumn
185- {
186- DataType = typeof ( string ) ,
187- MaxLength = - 1 ,
188- ColumnName = "MessageTemplate" ,
189-
190- } ;
191- eventsTable . Columns . Add ( messageTemplate ) ;
192- }
193-
194- if ( _columnOptions . Store . Contains ( StandardColumn . Level ) )
195- {
196- var level = new DataColumn
197- {
198- ColumnName = "Level"
199- } ;
200-
201- if ( _columnOptions . Level . StoreAsEnum )
202- {
203- level . DataType = typeof ( byte ) ;
204- }
205- else
206- {
207- level . DataType = typeof ( string ) ;
208- level . MaxLength = 128 ;
175+ case StandardColumn . Level :
176+ eventsTable . Columns . Add ( new DataColumn
177+ {
178+ DataType = _columnOptions . Level . StoreAsEnum ? typeof ( byte ) : typeof ( string ) ,
179+ MaxLength = _columnOptions . Level . StoreAsEnum ? 0 : 128 ,
180+ ColumnName = standardColumn . Value
181+ } ) ;
182+ break ;
183+ case StandardColumn . TimeStamp :
184+ eventsTable . Columns . Add ( new DataColumn
185+ {
186+ DataType = Type . GetType ( "System.DateTime" ) ,
187+ ColumnName = "TimeStamp" ,
188+ AllowDBNull = false
189+ } ) ;
190+ break ;
191+ case StandardColumn . LogEvent :
192+ eventsTable . Columns . Add ( new DataColumn
193+ {
194+ DataType = Type . GetType ( "System.String" ) ,
195+ ColumnName = "LogEvent"
196+ } ) ;
197+ break ;
198+ default :
199+ eventsTable . Columns . Add ( new DataColumn
200+ {
201+ DataType = typeof ( string ) ,
202+ MaxLength = - 1 ,
203+ ColumnName = standardColumn . Value
204+ } ) ;
205+ break ;
209206 }
210207
211- eventsTable . Columns . Add ( level ) ;
212- }
213-
214- if ( _columnOptions . Store . Contains ( StandardColumn . TimeStamp ) )
215- {
216- var timestamp = new DataColumn
217- {
218- DataType = Type . GetType ( "System.DateTime" ) ,
219- ColumnName = "TimeStamp" ,
220- AllowDBNull = false
221- } ;
222- eventsTable . Columns . Add ( timestamp ) ;
223- }
224-
225- if ( _columnOptions . Store . Contains ( StandardColumn . Exception ) )
226- {
227- var exception = new DataColumn
228- {
229- DataType = typeof ( string ) ,
230- MaxLength = - 1 ,
231- ColumnName = "Exception"
232- } ;
233- eventsTable . Columns . Add ( exception ) ;
234- }
235-
236- if ( _columnOptions . Store . Contains ( StandardColumn . Properties ) )
237- {
238- var props = new DataColumn
239- {
240- DataType = typeof ( string ) ,
241- MaxLength = - 1 ,
242- ColumnName = "Properties" ,
243- } ;
244- eventsTable . Columns . Add ( props ) ;
245- }
246-
247- if ( _columnOptions . Store . Contains ( StandardColumn . LogEvent ) )
248- {
249- var eventData = new DataColumn
250- {
251- DataType = Type . GetType ( "System.String" ) ,
252- ColumnName = "LogEvent"
253- } ;
254- eventsTable . Columns . Add ( eventData ) ;
255208 }
256209
257210 if ( _columnOptions . AdditionalDataColumns != null )
@@ -274,7 +227,7 @@ void FillDataTable(IEnumerable<LogEvent> events)
274227 {
275228 var row = _eventsTable . NewRow ( ) ;
276229
277- foreach ( var column in _columnOptions . Store )
230+ foreach ( var column in _columnOptions . Store . Keys )
278231 {
279232 switch ( column )
280233 {
0 commit comments