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.
@@ -20,35 +21,37 @@ public ColumnOptions()
20
21
21
22
Properties = new PropertiesColumnOptions ( ) ;
22
23
23
- Store = new Dictionary < StandardColumn , string >
24
+ Store = new Collection < StandardColumn >
24
25
{
25
- { StandardColumn . Message , StandardColumn . Message . ToString ( ) } ,
26
- { StandardColumn . MessageTemplate , StandardColumn . MessageTemplate . ToString ( ) } ,
27
- { StandardColumn . Level , StandardColumn . Level . ToString ( ) } ,
28
- { StandardColumn . TimeStamp , StandardColumn . TimeStamp . ToString ( ) } ,
29
- { StandardColumn . Exception , StandardColumn . Exception . ToString ( ) } ,
30
- { StandardColumn . Properties , StandardColumn . Properties . ToString ( ) }
26
+ StandardColumn . Message ,
27
+ StandardColumn . MessageTemplate ,
28
+ StandardColumn . Level ,
29
+ StandardColumn . TimeStamp ,
30
+ StandardColumn . Exception ,
31
+ StandardColumn . Properties
31
32
} ;
32
33
34
+ Message = new MessageColumnOptions ( ) ;
35
+ MessageTemplate = new MessageTemplateColumnOptions ( ) ;
33
36
TimeStamp = new TimeStampColumnOptions ( ) ;
34
-
37
+ Exception = new ExceptionColumnOptions ( ) ;
35
38
LogEvent = new LogEventColumnOptions ( ) ;
36
39
}
37
40
38
41
/// <summary>
39
42
/// A list of columns that will be stored in the logs table in the database.
40
43
/// </summary>
41
- public IDictionary < StandardColumn , string > Store
44
+ public ICollection < StandardColumn > Store
42
45
{
43
46
get { return _store ; }
44
47
set
45
48
{
46
49
if ( value == null )
47
50
{
48
- _store = new Dictionary < StandardColumn , string > ( ) ;
49
- foreach ( StandardColumn column in Enum . GetValues ( typeof ( StandardColumn ) ) )
51
+ _store = new Collection < StandardColumn > ( ) ;
52
+ foreach ( StandardColumn column in Enum . GetValues ( typeof ( StandardColumn ) ) )
50
53
{
51
- _store . Add ( column , column . ToString ( ) ) ;
54
+ _store . Add ( column ) ;
52
55
}
53
56
}
54
57
else
@@ -63,6 +66,21 @@ public IDictionary<StandardColumn, string> Store
63
66
/// </summary>
64
67
public ICollection < DataColumn > AdditionalDataColumns { get ; set ; }
65
68
69
+ /// <summary>
70
+ /// Options for the Exception column.
71
+ /// </summary>
72
+ public ExceptionColumnOptions Exception { get ; set ; }
73
+
74
+ /// <summary>
75
+ /// Options for the MessageTemplate column.
76
+ /// </summary>
77
+ public MessageTemplateColumnOptions MessageTemplate { get ; set ; }
78
+
79
+ /// <summary>
80
+ /// Options for the Message column.
81
+ /// </summary>
82
+ public MessageColumnOptions Message { get ; set ; }
83
+
66
84
/// <summary>
67
85
/// Options for the Level column.
68
86
/// </summary>
@@ -86,7 +104,7 @@ public IDictionary<StandardColumn, string> Store
86
104
/// <summary>
87
105
/// Options for the Level column.
88
106
/// </summary>
89
- public class LevelColumnOptions
107
+ public class LevelColumnOptions : CommonColumnOptions
90
108
{
91
109
/// <summary>
92
110
/// If true will store Level as an enum in a tinyint column as opposed to a string.
@@ -97,7 +115,7 @@ public class LevelColumnOptions
97
115
/// <summary>
98
116
/// Options for the Properties column.
99
117
/// </summary>
100
- public class PropertiesColumnOptions
118
+ public class PropertiesColumnOptions : CommonColumnOptions
101
119
{
102
120
/// <summary>
103
121
/// Default constructor.
@@ -174,10 +192,21 @@ public PropertiesColumnOptions()
174
192
public bool UsePropertyKeyAsElementName { get ; set ; }
175
193
}
176
194
195
+ /// <summary>
196
+ /// Shared column customization options.
197
+ /// </summary>
198
+ public class CommonColumnOptions
199
+ {
200
+ /// <summary>
201
+ /// The name of the column in the database.
202
+ /// </summary>
203
+ public string ColumnName { get ; set ; }
204
+ }
205
+
177
206
/// <summary>
178
207
/// Options for the TimeStamp column.
179
208
/// </summary>
180
- public class TimeStampColumnOptions
209
+ public class TimeStampColumnOptions : CommonColumnOptions
181
210
{
182
211
/// <summary>
183
212
/// If true, the time is converted to universal time.
@@ -188,12 +217,27 @@ public class TimeStampColumnOptions
188
217
/// <summary>
189
218
/// Options for the LogEvent column.
190
219
/// </summary>
191
- public class LogEventColumnOptions
220
+ public class LogEventColumnOptions : CommonColumnOptions
192
221
{
193
222
/// <summary>
194
223
/// Exclude properties from the LogEvent column if they are being saved to additional columns.
195
224
/// </summary>
196
225
public bool ExcludeAdditionalProperties { get ; set ; }
197
226
}
227
+
228
+ /// <summary>
229
+ /// Options for the message column
230
+ /// </summary>
231
+ public class MessageColumnOptions : CommonColumnOptions { }
232
+
233
+ /// <summary>
234
+ /// Options for the Exception column.
235
+ /// </summary>
236
+ public class ExceptionColumnOptions : CommonColumnOptions { }
237
+
238
+ /// <summary>
239
+ /// Options for the MessageTemplate column.
240
+ /// </summary>
241
+ public class MessageTemplateColumnOptions : CommonColumnOptions { }
198
242
}
199
- }
243
+ }
0 commit comments