44using Elastic . Transport ;
55using Serilog ;
66using Serilog . Configuration ;
7+ using Serilog . Core ;
8+ using Serilog . Events ;
79
810namespace Elastic . Serilog . Sinks
911{
@@ -17,7 +19,11 @@ public static class ElasticsearchSinkExtensions
1719 /// <para>Use <paramref name="loggerConfiguration"/> configure where and how data should be written</para>
1820 /// </summary>
1921 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+ ) ;
2127
2228 /// <summary>
2329 /// Write logs directly to Elasticsearch.
@@ -26,7 +32,11 @@ public static LoggerConfiguration Elasticsearch(this LoggerSinkConfiguration log
2632 /// </summary>
2733 public static LoggerConfiguration Elasticsearch < TEcsDocument > ( this LoggerSinkConfiguration loggerConfiguration , ElasticsearchSinkOptions < TEcsDocument > ? options = null )
2834 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+ ) ;
3040
3141 /// <summary>
3242 /// Write logs directly to Elasticsearch.
@@ -38,15 +48,18 @@ public static LoggerConfiguration Elasticsearch(
3848 ICollection < Uri > nodes ,
3949 Action < ElasticsearchSinkOptions > ? configureOptions = null ,
4050 Action < TransportConfiguration > ? configureTransport = null ,
41- bool useSniffing = true
51+ bool useSniffing = true ,
52+ LoggingLevelSwitch ? levelSwitch = null ,
53+ LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum
4254 )
4355 {
4456 var transportConfig = useSniffing ? TransportHelper . Static ( nodes ) : TransportHelper . Sniffing ( nodes ) ;
4557 configureTransport ? . Invoke ( transportConfig ) ;
58+
4659 var sinkOptions = new ElasticsearchSinkOptions ( new DefaultHttpTransport ( transportConfig ) ) ;
4760 configureOptions ? . Invoke ( sinkOptions ) ;
4861
49- return loggerConfiguration . Sink ( new ElasticsearchSink ( sinkOptions ) ) ;
62+ return loggerConfiguration . Sink ( new ElasticsearchSink ( sinkOptions ) , restrictedToMinimumLevel , levelSwitch ) ;
5063 }
5164
5265 /// <summary>
@@ -60,15 +73,17 @@ public static LoggerConfiguration Elasticsearch<TEcsDocument>(
6073 ICollection < Uri > nodes ,
6174 Action < ElasticsearchSinkOptions < TEcsDocument > > ? configureOptions = null ,
6275 Action < TransportConfiguration > ? configureTransport = null ,
63- bool useSniffing = true
76+ bool useSniffing = true ,
77+ LoggingLevelSwitch ? levelSwitch = null ,
78+ LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum
6479 ) where TEcsDocument : EcsDocument , new ( )
6580 {
6681 var transportConfig = useSniffing ? TransportHelper . Static ( nodes ) : TransportHelper . Sniffing ( nodes ) ;
6782 configureTransport ? . Invoke ( transportConfig ) ;
6883 var sinkOptions = new ElasticsearchSinkOptions < TEcsDocument > ( new DefaultHttpTransport ( transportConfig ) ) ;
6984 configureOptions ? . Invoke ( sinkOptions ) ;
7085
71- return loggerConfiguration . Sink ( new ElasticsearchSink < TEcsDocument > ( sinkOptions ) ) ;
86+ return loggerConfiguration . Sink ( new ElasticsearchSink < TEcsDocument > ( sinkOptions ) , restrictedToMinimumLevel , levelSwitch ) ;
7287 }
7388
7489 /// <summary>
@@ -82,15 +97,17 @@ public static LoggerConfiguration ElasticCloud(
8297 string cloudId ,
8398 string apiKey ,
8499 Action < ElasticsearchSinkOptions > ? configureOptions = null ,
85- Action < TransportConfiguration > ? configureTransport = null
100+ Action < TransportConfiguration > ? configureTransport = null ,
101+ LoggingLevelSwitch ? levelSwitch = null ,
102+ LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum
86103 )
87104 {
88105 var transportConfig = TransportHelper . Cloud ( cloudId , apiKey ) ;
89106 configureTransport ? . Invoke ( transportConfig ) ;
90107 var sinkOptions = new ElasticsearchSinkOptions ( new DefaultHttpTransport ( transportConfig ) ) ;
91108 configureOptions ? . Invoke ( sinkOptions ) ;
92109
93- return loggerConfiguration . Sink ( new ElasticsearchSink ( sinkOptions ) ) ;
110+ return loggerConfiguration . Sink ( new ElasticsearchSink ( sinkOptions ) , restrictedToMinimumLevel , levelSwitch ) ;
94111 }
95112
96113 /// <summary>
@@ -105,15 +122,17 @@ public static LoggerConfiguration ElasticCloud<TEcsDocument>(
105122 string cloudId ,
106123 string apiKey ,
107124 Action < ElasticsearchSinkOptions < TEcsDocument > > ? configureOptions = null ,
108- Action < TransportConfiguration > ? configureTransport = null
125+ Action < TransportConfiguration > ? configureTransport = null ,
126+ LoggingLevelSwitch ? levelSwitch = null ,
127+ LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum
109128 ) where TEcsDocument : EcsDocument , new ( )
110129 {
111130 var transportConfig = TransportHelper . Cloud ( cloudId , apiKey ) ;
112131 configureTransport ? . Invoke ( transportConfig ) ;
113132 var sinkOptions = new ElasticsearchSinkOptions < TEcsDocument > ( new DefaultHttpTransport ( transportConfig ) ) ;
114133 configureOptions ? . Invoke ( sinkOptions ) ;
115134
116- return loggerConfiguration . Sink ( new ElasticsearchSink < TEcsDocument > ( sinkOptions ) ) ;
135+ return loggerConfiguration . Sink ( new ElasticsearchSink < TEcsDocument > ( sinkOptions ) , restrictedToMinimumLevel , levelSwitch ) ;
117136 }
118137
119138 /// <summary>
@@ -128,15 +147,17 @@ public static LoggerConfiguration ElasticCloud(
128147 string username ,
129148 string password ,
130149 Action < ElasticsearchSinkOptions > ? configureOptions = null ,
131- Action < TransportConfiguration > ? configureTransport = null
150+ Action < TransportConfiguration > ? configureTransport = null ,
151+ LoggingLevelSwitch ? levelSwitch = null ,
152+ LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum
132153 )
133154 {
134155 var transportConfig = TransportHelper . Cloud ( cloudId , username , password ) ;
135156 configureTransport ? . Invoke ( transportConfig ) ;
136157 var sinkOptions = new ElasticsearchSinkOptions ( new DefaultHttpTransport ( transportConfig ) ) ;
137158 configureOptions ? . Invoke ( sinkOptions ) ;
138159
139- return loggerConfiguration . Sink ( new ElasticsearchSink ( sinkOptions ) ) ;
160+ return loggerConfiguration . Sink ( new ElasticsearchSink ( sinkOptions ) , restrictedToMinimumLevel , levelSwitch ) ;
140161 }
141162
142163 /// <summary>
@@ -152,15 +173,17 @@ public static LoggerConfiguration ElasticCloud<TEcsDocument>(
152173 string username ,
153174 string password ,
154175 Action < ElasticsearchSinkOptions < TEcsDocument > > ? configureOptions = null ,
155- Action < TransportConfiguration > ? configureTransport = null
176+ Action < TransportConfiguration > ? configureTransport = null ,
177+ LoggingLevelSwitch ? levelSwitch = null ,
178+ LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum
156179 ) where TEcsDocument : EcsDocument , new ( )
157180 {
158181 var transportConfig = TransportHelper . Cloud ( cloudId , username , password ) ;
159182 configureTransport ? . Invoke ( transportConfig ) ;
160183 var sinkOptions = new ElasticsearchSinkOptions < TEcsDocument > ( new DefaultHttpTransport ( transportConfig ) ) ;
161184 configureOptions ? . Invoke ( sinkOptions ) ;
162185
163- return loggerConfiguration . Sink ( new ElasticsearchSink < TEcsDocument > ( sinkOptions ) ) ;
186+ return loggerConfiguration . Sink ( new ElasticsearchSink < TEcsDocument > ( sinkOptions ) , restrictedToMinimumLevel , levelSwitch ) ;
164187 }
165188 }
166189}
0 commit comments