1
1
using System ;
2
2
using System . Collections . Generic ;
3
+ using System . Collections . ObjectModel ;
3
4
using System . Data ;
4
5
5
6
namespace Serilog . Sinks . MSSqlServer
@@ -9,7 +10,7 @@ namespace Serilog.Sinks.MSSqlServer
9
10
/// </summary>
10
11
public class ColumnOptions
11
12
{
12
- private IDictionary < StandardColumn , string > _store ;
13
+ ICollection < StandardColumn > _store ;
13
14
14
15
/// <summary>
15
16
/// Default constructor.
@@ -22,35 +23,37 @@ public ColumnOptions()
22
23
23
24
Properties = new PropertiesColumnOptions ( ) ;
24
25
25
- Store = new Dictionary < StandardColumn , string >
26
+ Store = new Collection < StandardColumn >
26
27
{
27
- { StandardColumn . Message , StandardColumn . Message . ToString ( ) } ,
28
- { StandardColumn . MessageTemplate , StandardColumn . MessageTemplate . ToString ( ) } ,
29
- { StandardColumn . Level , StandardColumn . Level . ToString ( ) } ,
30
- { StandardColumn . TimeStamp , StandardColumn . TimeStamp . ToString ( ) } ,
31
- { StandardColumn . Exception , StandardColumn . Exception . ToString ( ) } ,
32
- { StandardColumn . Properties , StandardColumn . Properties . ToString ( ) }
28
+ StandardColumn . Message ,
29
+ StandardColumn . MessageTemplate ,
30
+ StandardColumn . Level ,
31
+ StandardColumn . TimeStamp ,
32
+ StandardColumn . Exception ,
33
+ StandardColumn . Properties
33
34
} ;
34
35
36
+ Message = new MessageColumnOptions ( ) ;
37
+ MessageTemplate = new MessageTemplateColumnOptions ( ) ;
35
38
TimeStamp = new TimeStampColumnOptions ( ) ;
36
-
39
+ Exception = new ExceptionColumnOptions ( ) ;
37
40
LogEvent = new LogEventColumnOptions ( ) ;
38
41
}
39
42
40
43
/// <summary>
41
44
/// A list of columns that will be stored in the logs table in the database.
42
45
/// </summary>
43
- public IDictionary < StandardColumn , string > Store
46
+ public ICollection < StandardColumn > Store
44
47
{
45
48
get { return _store ; }
46
49
set
47
50
{
48
51
if ( value == null )
49
52
{
50
- _store = new Dictionary < StandardColumn , string > ( ) ;
51
- foreach ( StandardColumn column in Enum . GetValues ( typeof ( StandardColumn ) ) )
53
+ _store = new Collection < StandardColumn > ( ) ;
54
+ foreach ( StandardColumn column in Enum . GetValues ( typeof ( StandardColumn ) ) )
52
55
{
53
- _store . Add ( column , column . ToString ( ) ) ;
56
+ _store . Add ( column ) ;
54
57
}
55
58
}
56
59
else
@@ -65,10 +68,19 @@ public IDictionary<StandardColumn, string> Store
65
68
/// </summary>
66
69
public ICollection < DataColumn > AdditionalDataColumns { get ; set ; }
67
70
71
+ /// Options for the Exception column.
72
+ /// </summary>
73
+ public ExceptionColumnOptions Exception { get ; set ; }
74
+
68
75
/// <summary>
69
- /// Options for the Id column.
76
+ /// Options for the MessageTemplate column.
77
+ /// </summary>
78
+ public MessageTemplateColumnOptions MessageTemplate { get ; set ; }
79
+
80
+ /// <summary>
81
+ /// Options for the Message column.
70
82
/// </summary>
71
- public IdColumnOptions Id { get ; private set ; }
83
+ public MessageColumnOptions Message { get ; set ; }
72
84
73
85
/// <summary>
74
86
/// Options for the Level column.
@@ -104,7 +116,7 @@ public class IdColumnOptions
104
116
/// <summary>
105
117
/// Options for the Level column.
106
118
/// </summary>
107
- public class LevelColumnOptions
119
+ public class LevelColumnOptions : CommonColumnOptions
108
120
{
109
121
/// <summary>
110
122
/// If true will store Level as an enum in a tinyint column as opposed to a string.
@@ -115,7 +127,7 @@ public class LevelColumnOptions
115
127
/// <summary>
116
128
/// Options for the Properties column.
117
129
/// </summary>
118
- public class PropertiesColumnOptions
130
+ public class PropertiesColumnOptions : CommonColumnOptions
119
131
{
120
132
/// <summary>
121
133
/// Default constructor.
@@ -192,10 +204,21 @@ public PropertiesColumnOptions()
192
204
public bool UsePropertyKeyAsElementName { get ; set ; }
193
205
}
194
206
207
+ /// <summary>
208
+ /// Shared column customization options.
209
+ /// </summary>
210
+ public class CommonColumnOptions
211
+ {
212
+ /// <summary>
213
+ /// The name of the column in the database.
214
+ /// </summary>
215
+ public string ColumnName { get ; set ; }
216
+ }
217
+
195
218
/// <summary>
196
219
/// Options for the TimeStamp column.
197
220
/// </summary>
198
- public class TimeStampColumnOptions
221
+ public class TimeStampColumnOptions : CommonColumnOptions
199
222
{
200
223
/// <summary>
201
224
/// If true, the time is converted to universal time.
@@ -206,12 +229,27 @@ public class TimeStampColumnOptions
206
229
/// <summary>
207
230
/// Options for the LogEvent column.
208
231
/// </summary>
209
- public class LogEventColumnOptions
232
+ public class LogEventColumnOptions : CommonColumnOptions
210
233
{
211
234
/// <summary>
212
235
/// Exclude properties from the LogEvent column if they are being saved to additional columns.
213
236
/// </summary>
214
237
public bool ExcludeAdditionalProperties { get ; set ; }
215
238
}
239
+
240
+ /// <summary>
241
+ /// Options for the message column
242
+ /// </summary>
243
+ public class MessageColumnOptions : CommonColumnOptions { }
244
+
245
+ /// <summary>
246
+ /// Options for the Exception column.
247
+ /// </summary>
248
+ public class ExceptionColumnOptions : CommonColumnOptions { }
249
+
250
+ /// <summary>
251
+ /// Options for the MessageTemplate column.
252
+ /// </summary>
253
+ public class MessageTemplateColumnOptions : CommonColumnOptions { }
216
254
}
217
- }
255
+ }
0 commit comments