1313// limitations under the License.
1414
1515
16- using System ;
17- using System . Net . Http ;
1816using Serilog . Configuration ;
1917using Serilog . Core ;
2018using Serilog . Events ;
2119using Serilog . Formatting ;
20+ using Serilog . Formatting . Json ;
2221using Serilog . Sinks . PeriodicBatching ;
2322using Serilog . Sinks . Splunk ;
23+ using System ;
24+ using System . Net . Http ;
2425
2526namespace Serilog
2627{
@@ -64,25 +65,33 @@ public static LoggerConfiguration EventCollector(
6465 int batchIntervalInSeconds = 2 ,
6566 int batchSizeLimit = 100 ,
6667 int ? queueLimit = null ,
67- HttpMessageHandler messageHandler = null ,
68+ HttpMessageHandler messageHandler = null ,
6869 LoggingLevelSwitch levelSwitch = null )
6970 {
7071 if ( configuration == null ) throw new ArgumentNullException ( nameof ( configuration ) ) ;
7172
73+ var batchingOptions = new PeriodicBatchingSinkOptions
74+ {
75+ BatchSizeLimit = batchSizeLimit ,
76+ Period = TimeSpan . FromSeconds ( batchIntervalInSeconds ) ,
77+ EagerlyEmitFirstEvent = true ,
78+ QueueLimit = queueLimit
79+ } ;
80+
7281 var eventCollectorSink = new EventCollectorSink (
7382 splunkHost ,
74- eventCollectorToken ,
83+ eventCollectorToken ,
7584 uriPath ,
76- source ,
77- sourceType ,
78- host ,
85+ source ,
86+ sourceType ,
87+ host ,
7988 index ,
8089 formatProvider ,
8190 renderTemplate ,
8291 messageHandler ) ;
92+ var batchingSink = new PeriodicBatchingSink ( eventCollectorSink , batchingOptions ) ;
8393
84- return configuration . BuildPeriodicBatchingSink ( eventCollectorSink , restrictedToMinimumLevel , levelSwitch ,
85- batchIntervalInSeconds , batchSizeLimit , queueLimit ) ;
94+ return configuration . Sink ( batchingSink , restrictedToMinimumLevel , levelSwitch ) ;
8695 }
8796
8897 /// <summary>
@@ -117,16 +126,25 @@ public static LoggerConfiguration EventCollector(
117126 if ( configuration == null ) throw new ArgumentNullException ( nameof ( configuration ) ) ;
118127 if ( jsonFormatter == null ) throw new ArgumentNullException ( nameof ( jsonFormatter ) ) ;
119128
129+
130+ var batchingOptions = new PeriodicBatchingSinkOptions
131+ {
132+ BatchSizeLimit = batchSizeLimit ,
133+ Period = TimeSpan . FromSeconds ( batchIntervalInSeconds ) ,
134+ EagerlyEmitFirstEvent = true ,
135+ QueueLimit = queueLimit
136+ } ;
137+
120138 var eventCollectorSink = new EventCollectorSink (
121139 splunkHost ,
122140 eventCollectorToken ,
123141 uriPath ,
124-
125142 jsonFormatter ,
126143 messageHandler ) ;
127144
128- return configuration . BuildPeriodicBatchingSink ( eventCollectorSink , restrictedToMinimumLevel , levelSwitch ,
129- batchIntervalInSeconds , batchSizeLimit , queueLimit ) ;
145+ var batchingSink = new PeriodicBatchingSink ( eventCollectorSink , batchingOptions ) ;
146+
147+ return configuration . Sink ( batchingSink , restrictedToMinimumLevel , levelSwitch ) ;
130148 }
131149
132150
@@ -172,39 +190,30 @@ public static LoggerConfiguration EventCollector(
172190 {
173191 if ( configuration == null ) throw new ArgumentNullException ( nameof ( configuration ) ) ;
174192
175- var eventCollectorSink = new EventCollectorSink (
176- splunkHost ,
177- eventCollectorToken ,
178- uriPath ,
179- source ,
180- sourceType ,
181- host ,
182- index ,
183- fields ,
184- formatProvider ,
185- renderTemplate ,
186- messageHandler
187- ) ;
188-
189- return configuration . BuildPeriodicBatchingSink ( eventCollectorSink , restrictedToMinimumLevel , levelSwitch ,
190- batchIntervalInSeconds , batchSizeLimit , queueLimit ) ;
191- }
192-
193- private static LoggerConfiguration BuildPeriodicBatchingSink ( this LoggerSinkConfiguration configuration ,
194- EventCollectorSink eventCollectorSink ,
195- LogEventLevel restrictedToMinimumLevel ,
196- LoggingLevelSwitch levelSwitch = null ,
197- int batchIntervalInSeconds = 2 ,
198- int batchSizeLimit = 100 ,
199- int ? queueLimit = EventCollectorSink . DefaultQueueLimit )
200- {
201- var periodicBatchingOptions = new PeriodicBatchingSinkOptions
193+ var batchingOptions = new PeriodicBatchingSinkOptions
202194 {
203- Period = TimeSpan . FromSeconds ( batchIntervalInSeconds ) , QueueLimit = queueLimit , BatchSizeLimit = batchSizeLimit
195+ BatchSizeLimit = batchSizeLimit ,
196+ Period = TimeSpan . FromSeconds ( batchIntervalInSeconds ) ,
197+ EagerlyEmitFirstEvent = true ,
198+ QueueLimit = queueLimit
204199 } ;
205- var periodicBatchSink = new PeriodicBatchingSink ( eventCollectorSink , periodicBatchingOptions ) ;
206200
207- return configuration . Sink ( periodicBatchSink , restrictedToMinimumLevel , levelSwitch ) ;
201+ var eventCollectorSink = new EventCollectorSink (
202+ splunkHost ,
203+ eventCollectorToken ,
204+ uriPath ,
205+ source ,
206+ sourceType ,
207+ host ,
208+ index ,
209+ fields ,
210+ formatProvider ,
211+ renderTemplate ,
212+ messageHandler ) ;
213+
214+ var batchingSink = new PeriodicBatchingSink ( eventCollectorSink , batchingOptions ) ;
215+
216+ return configuration . Sink ( batchingSink , restrictedToMinimumLevel , levelSwitch ) ;
208217 }
209218 }
210219}
0 commit comments