24
24
using Serilog . Core ;
25
25
using Serilog . Debugging ;
26
26
using Serilog . Events ;
27
+ using Serilog . Formatting ;
27
28
28
29
namespace Serilog . Sinks . Splunk
29
30
{
@@ -35,7 +36,7 @@ public class EventCollectorSink : ILogEventSink, IDisposable
35
36
private readonly string _splunkHost ;
36
37
private readonly string _uriPath ;
37
38
private readonly int _batchSizeLimitLimit ;
38
- private readonly SplunkJsonFormatter _jsonFormatter ;
39
+ private readonly ITextFormatter _jsonFormatter ;
39
40
private readonly ConcurrentQueue < LogEvent > _queue ;
40
41
private readonly EventCollectorClient _httpClient ;
41
42
@@ -68,8 +69,8 @@ public EventCollectorSink(
68
69
: this (
69
70
splunkHost ,
70
71
eventCollectorToken ,
71
- null , null , null , null , null ,
72
- batchIntervalInSeconds ,
72
+ null , null , null , null , null ,
73
+ batchIntervalInSeconds ,
73
74
batchSizeLimit ,
74
75
formatProvider ,
75
76
renderTemplate )
@@ -104,11 +105,41 @@ public EventCollectorSink(
104
105
IFormatProvider formatProvider = null ,
105
106
bool renderTemplate = true ,
106
107
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 )
107
138
{
108
139
_uriPath = uriPath ;
109
140
_splunkHost = splunkHost ;
110
141
_queue = new ConcurrentQueue < LogEvent > ( ) ;
111
- _jsonFormatter = new SplunkJsonFormatter ( renderTemplate , formatProvider , source , sourceType , host , index ) ;
142
+ _jsonFormatter = jsonFormatter ;
112
143
_batchSizeLimitLimit = batchSizeLimit ;
113
144
114
145
var batchInterval = TimeSpan . FromSeconds ( batchIntervalInSeconds ) ;
0 commit comments