4
4
using Elastic . Transport ;
5
5
using Serilog ;
6
6
using Serilog . Configuration ;
7
+ using Serilog . Core ;
8
+ using Serilog . Events ;
7
9
8
10
namespace Elastic . Serilog . Sinks
9
11
{
@@ -17,7 +19,11 @@ public static class ElasticsearchSinkExtensions
17
19
/// <para>Use <paramref name="loggerConfiguration"/> configure where and how data should be written</para>
18
20
/// </summary>
19
21
public static LoggerConfiguration Elasticsearch ( this LoggerSinkConfiguration loggerConfiguration , ElasticsearchSinkOptions ? options = null ) =>
20
- loggerConfiguration . Sink ( new ElasticsearchSink ( options ?? new ElasticsearchSinkOptions ( ) ) ) ;
22
+ loggerConfiguration . Sink (
23
+ new ElasticsearchSink ( options ?? new ElasticsearchSinkOptions ( ) )
24
+ , restrictedToMinimumLevel : options ? . MinimumLevel ?? LevelAlias . Minimum
25
+ , levelSwitch : options ? . LevelSwitch
26
+ ) ;
21
27
22
28
/// <summary>
23
29
/// Write logs directly to Elasticsearch.
@@ -26,7 +32,11 @@ public static LoggerConfiguration Elasticsearch(this LoggerSinkConfiguration log
26
32
/// </summary>
27
33
public static LoggerConfiguration Elasticsearch < TEcsDocument > ( this LoggerSinkConfiguration loggerConfiguration , ElasticsearchSinkOptions < TEcsDocument > ? options = null )
28
34
where TEcsDocument : EcsDocument , new ( ) =>
29
- loggerConfiguration . Sink ( new ElasticsearchSink < TEcsDocument > ( options ?? new ElasticsearchSinkOptions < TEcsDocument > ( ) ) ) ;
35
+ loggerConfiguration . Sink (
36
+ new ElasticsearchSink < TEcsDocument > ( options ?? new ElasticsearchSinkOptions < TEcsDocument > ( ) )
37
+ , restrictedToMinimumLevel : options ? . MinimumLevel ?? LevelAlias . Minimum
38
+ , levelSwitch : options ? . LevelSwitch
39
+ ) ;
30
40
31
41
/// <summary>
32
42
/// Write logs directly to Elasticsearch.
@@ -38,15 +48,18 @@ public static LoggerConfiguration Elasticsearch(
38
48
ICollection < Uri > nodes ,
39
49
Action < ElasticsearchSinkOptions > ? configureOptions = null ,
40
50
Action < TransportConfiguration > ? configureTransport = null ,
41
- bool useSniffing = true
51
+ bool useSniffing = true ,
52
+ LoggingLevelSwitch ? levelSwitch = null ,
53
+ LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum
42
54
)
43
55
{
44
56
var transportConfig = useSniffing ? TransportHelper . Static ( nodes ) : TransportHelper . Sniffing ( nodes ) ;
45
57
configureTransport ? . Invoke ( transportConfig ) ;
58
+
46
59
var sinkOptions = new ElasticsearchSinkOptions ( new DefaultHttpTransport ( transportConfig ) ) ;
47
60
configureOptions ? . Invoke ( sinkOptions ) ;
48
61
49
- return loggerConfiguration . Sink ( new ElasticsearchSink ( sinkOptions ) ) ;
62
+ return loggerConfiguration . Sink ( new ElasticsearchSink ( sinkOptions ) , restrictedToMinimumLevel , levelSwitch ) ;
50
63
}
51
64
52
65
/// <summary>
@@ -60,15 +73,17 @@ public static LoggerConfiguration Elasticsearch<TEcsDocument>(
60
73
ICollection < Uri > nodes ,
61
74
Action < ElasticsearchSinkOptions < TEcsDocument > > ? configureOptions = null ,
62
75
Action < TransportConfiguration > ? configureTransport = null ,
63
- bool useSniffing = true
76
+ bool useSniffing = true ,
77
+ LoggingLevelSwitch ? levelSwitch = null ,
78
+ LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum
64
79
) where TEcsDocument : EcsDocument , new ( )
65
80
{
66
81
var transportConfig = useSniffing ? TransportHelper . Static ( nodes ) : TransportHelper . Sniffing ( nodes ) ;
67
82
configureTransport ? . Invoke ( transportConfig ) ;
68
83
var sinkOptions = new ElasticsearchSinkOptions < TEcsDocument > ( new DefaultHttpTransport ( transportConfig ) ) ;
69
84
configureOptions ? . Invoke ( sinkOptions ) ;
70
85
71
- return loggerConfiguration . Sink ( new ElasticsearchSink < TEcsDocument > ( sinkOptions ) ) ;
86
+ return loggerConfiguration . Sink ( new ElasticsearchSink < TEcsDocument > ( sinkOptions ) , restrictedToMinimumLevel , levelSwitch ) ;
72
87
}
73
88
74
89
/// <summary>
@@ -82,15 +97,17 @@ public static LoggerConfiguration ElasticCloud(
82
97
string cloudId ,
83
98
string apiKey ,
84
99
Action < ElasticsearchSinkOptions > ? configureOptions = null ,
85
- Action < TransportConfiguration > ? configureTransport = null
100
+ Action < TransportConfiguration > ? configureTransport = null ,
101
+ LoggingLevelSwitch ? levelSwitch = null ,
102
+ LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum
86
103
)
87
104
{
88
105
var transportConfig = TransportHelper . Cloud ( cloudId , apiKey ) ;
89
106
configureTransport ? . Invoke ( transportConfig ) ;
90
107
var sinkOptions = new ElasticsearchSinkOptions ( new DefaultHttpTransport ( transportConfig ) ) ;
91
108
configureOptions ? . Invoke ( sinkOptions ) ;
92
109
93
- return loggerConfiguration . Sink ( new ElasticsearchSink ( sinkOptions ) ) ;
110
+ return loggerConfiguration . Sink ( new ElasticsearchSink ( sinkOptions ) , restrictedToMinimumLevel , levelSwitch ) ;
94
111
}
95
112
96
113
/// <summary>
@@ -105,15 +122,17 @@ public static LoggerConfiguration ElasticCloud<TEcsDocument>(
105
122
string cloudId ,
106
123
string apiKey ,
107
124
Action < ElasticsearchSinkOptions < TEcsDocument > > ? configureOptions = null ,
108
- Action < TransportConfiguration > ? configureTransport = null
125
+ Action < TransportConfiguration > ? configureTransport = null ,
126
+ LoggingLevelSwitch ? levelSwitch = null ,
127
+ LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum
109
128
) where TEcsDocument : EcsDocument , new ( )
110
129
{
111
130
var transportConfig = TransportHelper . Cloud ( cloudId , apiKey ) ;
112
131
configureTransport ? . Invoke ( transportConfig ) ;
113
132
var sinkOptions = new ElasticsearchSinkOptions < TEcsDocument > ( new DefaultHttpTransport ( transportConfig ) ) ;
114
133
configureOptions ? . Invoke ( sinkOptions ) ;
115
134
116
- return loggerConfiguration . Sink ( new ElasticsearchSink < TEcsDocument > ( sinkOptions ) ) ;
135
+ return loggerConfiguration . Sink ( new ElasticsearchSink < TEcsDocument > ( sinkOptions ) , restrictedToMinimumLevel , levelSwitch ) ;
117
136
}
118
137
119
138
/// <summary>
@@ -128,15 +147,17 @@ public static LoggerConfiguration ElasticCloud(
128
147
string username ,
129
148
string password ,
130
149
Action < ElasticsearchSinkOptions > ? configureOptions = null ,
131
- Action < TransportConfiguration > ? configureTransport = null
150
+ Action < TransportConfiguration > ? configureTransport = null ,
151
+ LoggingLevelSwitch ? levelSwitch = null ,
152
+ LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum
132
153
)
133
154
{
134
155
var transportConfig = TransportHelper . Cloud ( cloudId , username , password ) ;
135
156
configureTransport ? . Invoke ( transportConfig ) ;
136
157
var sinkOptions = new ElasticsearchSinkOptions ( new DefaultHttpTransport ( transportConfig ) ) ;
137
158
configureOptions ? . Invoke ( sinkOptions ) ;
138
159
139
- return loggerConfiguration . Sink ( new ElasticsearchSink ( sinkOptions ) ) ;
160
+ return loggerConfiguration . Sink ( new ElasticsearchSink ( sinkOptions ) , restrictedToMinimumLevel , levelSwitch ) ;
140
161
}
141
162
142
163
/// <summary>
@@ -152,15 +173,17 @@ public static LoggerConfiguration ElasticCloud<TEcsDocument>(
152
173
string username ,
153
174
string password ,
154
175
Action < ElasticsearchSinkOptions < TEcsDocument > > ? configureOptions = null ,
155
- Action < TransportConfiguration > ? configureTransport = null
176
+ Action < TransportConfiguration > ? configureTransport = null ,
177
+ LoggingLevelSwitch ? levelSwitch = null ,
178
+ LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum
156
179
) where TEcsDocument : EcsDocument , new ( )
157
180
{
158
181
var transportConfig = TransportHelper . Cloud ( cloudId , username , password ) ;
159
182
configureTransport ? . Invoke ( transportConfig ) ;
160
183
var sinkOptions = new ElasticsearchSinkOptions < TEcsDocument > ( new DefaultHttpTransport ( transportConfig ) ) ;
161
184
configureOptions ? . Invoke ( sinkOptions ) ;
162
185
163
- return loggerConfiguration . Sink ( new ElasticsearchSink < TEcsDocument > ( sinkOptions ) ) ;
186
+ return loggerConfiguration . Sink ( new ElasticsearchSink < TEcsDocument > ( sinkOptions ) , restrictedToMinimumLevel , levelSwitch ) ;
164
187
}
165
188
}
166
189
}
0 commit comments