2424using Serilog . Core ;
2525using Serilog . Debugging ;
2626using Serilog . Events ;
27+ using Serilog . Formatting ;
2728
2829namespace Serilog . Sinks . Splunk
2930{
@@ -35,7 +36,7 @@ public class EventCollectorSink : ILogEventSink, IDisposable
3536 private readonly string _splunkHost ;
3637 private readonly string _uriPath ;
3738 private readonly int _batchSizeLimitLimit ;
38- private readonly SplunkJsonFormatter _jsonFormatter ;
39+ private readonly ITextFormatter _jsonFormatter ;
3940 private readonly ConcurrentQueue < LogEvent > _queue ;
4041 private readonly EventCollectorClient _httpClient ;
4142
@@ -68,8 +69,8 @@ public EventCollectorSink(
6869 : this (
6970 splunkHost ,
7071 eventCollectorToken ,
71- null , null , null , null , null ,
72- batchIntervalInSeconds ,
72+ null , null , null , null , null ,
73+ batchIntervalInSeconds ,
7374 batchSizeLimit ,
7475 formatProvider ,
7576 renderTemplate )
@@ -104,11 +105,41 @@ public EventCollectorSink(
104105 IFormatProvider formatProvider = null ,
105106 bool renderTemplate = true ,
106107 HttpMessageHandler messageHandler = null )
108+ : this (
109+ splunkHost ,
110+ eventCollectorToken ,
111+ uriPath ,
112+ batchIntervalInSeconds ,
113+ batchSizeLimit ,
114+ new SplunkJsonFormatter ( renderTemplate , formatProvider , source , sourceType , host , index ) ,
115+ messageHandler )
116+ {
117+ }
118+
119+
120+ /// <summary>
121+ /// Creates a new instance of the sink
122+ /// </summary>
123+ /// <param name="splunkHost">The host of the Splunk instance with the Event collector configured</param>
124+ /// <param name="eventCollectorToken">The token to use when authenticating with the event collector</param>
125+ /// <param name="uriPath">Change the default endpoint of the Event Collector e.g. services/collector/event</param>
126+ /// <param name="batchSizeLimit">The size of the batch when sending to the event collector</param>
127+ /// <param name="batchIntervalInSeconds">The interval in seconds that batching should occur</param>
128+ /// <param name="jsonFormatter">The text formatter used to render log events into a JSON format for consumption by Splunk</param>
129+ /// <param name="messageHandler">The handler used to send HTTP requests</param>
130+ public EventCollectorSink (
131+ string splunkHost ,
132+ string eventCollectorToken ,
133+ string uriPath ,
134+ int batchIntervalInSeconds ,
135+ int batchSizeLimit ,
136+ ITextFormatter jsonFormatter ,
137+ HttpMessageHandler messageHandler = null )
107138 {
108139 _uriPath = uriPath ;
109140 _splunkHost = splunkHost ;
110141 _queue = new ConcurrentQueue < LogEvent > ( ) ;
111- _jsonFormatter = new SplunkJsonFormatter ( renderTemplate , formatProvider , source , sourceType , host , index ) ;
142+ _jsonFormatter = jsonFormatter ;
112143 _batchSizeLimitLimit = batchSizeLimit ;
113144
114145 var batchInterval = TimeSpan . FromSeconds ( batchIntervalInSeconds ) ;
0 commit comments