@@ -21,19 +21,31 @@ public class SplunkViaEventCollectorSink : ILogEventSink
21
21
{
22
22
private string _splunkHost ;
23
23
private string _eventCollectorToken ;
24
- private int _batchSizeLimit ;
24
+ private int _batchSizeLimitLimit ;
25
25
private JsonFormatter _jsonFormatter ;
26
26
private ConcurrentQueue < LogEvent > _queue ;
27
+ private TimeSpan _batchInterval ;
28
+
29
+
30
+ //public const int DefaultBatchInterval = 10 * 1000; // 10 seconds
31
+ //public const int DefaultBatchSize = 10 * 1024; // 10KB
32
+ //public const int DefaultBatchCount = 10;
33
+
27
34
28
35
/// <summary>
29
36
/// Creates a new instance of the sink
30
37
/// </summary>
31
38
/// <param name="splunkHost"></param>
32
39
/// <param name="eventCollectorToken"></param>
40
+ /// <param name="batchSizeLimit"></param>
33
41
/// <param name="formatProvider"></param>
34
42
/// <param name="renderTemplate"></param>
35
- public SplunkViaEventCollectorSink ( string splunkHost ,
43
+ /// <param name="batchIntervalInSeconds"></param>
44
+ public SplunkViaEventCollectorSink (
45
+ string splunkHost ,
36
46
string eventCollectorToken ,
47
+ int batchIntervalInSeconds = 10 ,
48
+ int batchSizeLimit = 10 ,
37
49
IFormatProvider formatProvider = null ,
38
50
bool renderTemplate = true
39
51
)
@@ -42,11 +54,11 @@ public SplunkViaEventCollectorSink(string splunkHost,
42
54
_eventCollectorToken = eventCollectorToken ;
43
55
_queue = new ConcurrentQueue < LogEvent > ( ) ;
44
56
45
- _jsonFormatter = new JsonFormatter ( renderMessage : true , formatProvider : formatProvider ) ;
46
- _batchSizeLimit = 1 ;
47
- var batchInterval = TimeSpan . FromSeconds ( 5 ) ;
57
+ _jsonFormatter = new SplunkJsonFormatter ( renderMessage : true , formatProvider : formatProvider , renderTemplate : renderTemplate ) ;
58
+ _batchSizeLimitLimit = batchSizeLimit ;
59
+ _batchInterval = TimeSpan . FromSeconds ( batchIntervalInSeconds ) ;
48
60
49
- RepeatAction . OnInterval ( batchInterval , ( ) => ProcessQueue ( ) . Wait ( ) , new CancellationToken ( ) ) ;
61
+ RepeatAction . OnInterval ( _batchInterval , ( ) => ProcessQueue ( ) . Wait ( ) , new CancellationToken ( ) ) ;
50
62
}
51
63
52
64
/// <summary>
@@ -70,7 +82,7 @@ private async Task ProcessQueue()
70
82
var events = new Queue < LogEvent > ( ) ;
71
83
LogEvent next ;
72
84
73
- while ( count < _batchSizeLimit && _queue . TryDequeue ( out next ) )
85
+ while ( count < _batchSizeLimitLimit && _queue . TryDequeue ( out next ) )
74
86
{
75
87
count ++ ;
76
88
events . Enqueue ( next ) ;
@@ -80,10 +92,14 @@ private async Task ProcessQueue()
80
92
return ;
81
93
82
94
var sw = new StringWriter ( ) ;
95
+
96
+ //TODO: Check status code against defaults
97
+ //TODO: Put items back in queue if matching use case
98
+ //TODO: Change to use retry methods
83
99
100
+
84
101
foreach ( var logEvent in events )
85
- {
86
-
102
+ {
87
103
_jsonFormatter . Format ( logEvent , sw ) ;
88
104
89
105
var logEventAsAString = sw . ToString ( ) ;
0 commit comments