Skip to content

Commit d79a716

Browse files
authored
Merge pull request #134 from JuanjoFuchs/QueueLimitParameterAdded
Added QueueLimit parameter and passing to base PeriodicBatchingSink
2 parents 01af224 + eb30e85 commit d79a716

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/Serilog.Sinks.Splunk/Sinks/Splunk/EventCollectorSink.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ namespace Serilog.Sinks.Splunk
3131
/// </summary>
3232
public class EventCollectorSink : PeriodicBatchingSink
3333
{
34+
private const int NoQueueLimit = -1;
35+
3436
private readonly string _splunkHost;
3537
private readonly string _uriPath;
3638
private readonly ITextFormatter _jsonFormatter;
@@ -56,11 +58,13 @@ public class EventCollectorSink : PeriodicBatchingSink
5658
/// <param name="formatProvider">The format provider used when rendering the message</param>
5759
/// <param name="renderTemplate">Whether to render the message template</param>
5860
/// <param name="batchIntervalInSeconds">The interval in seconds that batching should occur</param>
61+
/// <param name="queueLimit">Maximum number of events in the queue</param>
5962
public EventCollectorSink(
6063
string splunkHost,
6164
string eventCollectorToken,
6265
int batchIntervalInSeconds = 5,
6366
int batchSizeLimit = 100,
67+
int? queueLimit = null,
6468
IFormatProvider formatProvider = null,
6569
bool renderTemplate = true)
6670
: this(
@@ -69,6 +73,7 @@ public EventCollectorSink(
6973
null, null, null, null, null,
7074
batchIntervalInSeconds,
7175
batchSizeLimit,
76+
queueLimit,
7277
formatProvider,
7378
renderTemplate)
7479
{
@@ -84,6 +89,7 @@ public EventCollectorSink(
8489
/// <param name="formatProvider">The format provider used when rendering the message</param>
8590
/// <param name="renderTemplate">Whether to render the message template</param>
8691
/// <param name="batchIntervalInSeconds">The interval in seconds that batching should occur</param>
92+
/// <param name="queueLimit">Maximum number of events in the queue</param>
8793
/// <param name="index">The Splunk index to log to</param>
8894
/// <param name="source">The source of the event</param>
8995
/// <param name="sourceType">The source type of the event</param>
@@ -99,6 +105,7 @@ public EventCollectorSink(
99105
string index,
100106
int batchIntervalInSeconds,
101107
int batchSizeLimit,
108+
int? queueLimit,
102109
IFormatProvider formatProvider = null,
103110
bool renderTemplate = true,
104111
HttpMessageHandler messageHandler = null)
@@ -108,6 +115,7 @@ public EventCollectorSink(
108115
uriPath,
109116
batchIntervalInSeconds,
110117
batchSizeLimit,
118+
queueLimit,
111119
new SplunkJsonFormatter(renderTemplate, formatProvider, source, sourceType, host, index),
112120
messageHandler)
113121
{
@@ -120,6 +128,7 @@ public EventCollectorSink(
120128
/// <param name="eventCollectorToken">The token to use when authenticating with the event collector</param>
121129
/// <param name="uriPath">Change the default endpoint of the Event Collector e.g. services/collector/event</param>
122130
/// <param name="batchSizeLimit">The size of the batch when sending to the event collector</param>
131+
/// <param name="queueLimit">Maximum number of events in the queue</param>
123132
/// <param name="formatProvider">The format provider used when rendering the message</param>
124133
/// <param name="renderTemplate">Whether to render the message template</param>
125134
/// <param name="batchIntervalInSeconds">The interval in seconds that batching should occur</param>
@@ -140,6 +149,7 @@ public EventCollectorSink(
140149
CustomFields fields,
141150
int batchIntervalInSeconds,
142151
int batchSizeLimit,
152+
int? queueLimit,
143153
IFormatProvider formatProvider = null,
144154
bool renderTemplate = true,
145155
HttpMessageHandler messageHandler = null)
@@ -150,6 +160,7 @@ public EventCollectorSink(
150160
uriPath,
151161
batchIntervalInSeconds,
152162
batchSizeLimit,
163+
queueLimit,
153164
new SplunkJsonFormatter(renderTemplate, formatProvider, source, sourceType, host, index, fields),
154165
messageHandler)
155166
{
@@ -163,6 +174,7 @@ public EventCollectorSink(
163174
/// <param name="uriPath">Change the default endpoint of the Event Collector e.g. services/collector/event</param>
164175
/// <param name="batchSizeLimit">The size of the batch when sending to the event collector</param>
165176
/// <param name="batchIntervalInSeconds">The interval in seconds that batching should occur</param>
177+
/// <param name="queueLimit">Maximum number of events in the queue</param>
166178
/// <param name="jsonFormatter">The text formatter used to render log events into a JSON format for consumption by Splunk</param>
167179
/// <param name="messageHandler">The handler used to send HTTP requests</param>
168180
public EventCollectorSink(
@@ -171,9 +183,10 @@ public EventCollectorSink(
171183
string uriPath,
172184
int batchIntervalInSeconds,
173185
int batchSizeLimit,
186+
int? queueLimit,
174187
ITextFormatter jsonFormatter,
175188
HttpMessageHandler messageHandler = null)
176-
: base(batchSizeLimit, TimeSpan.FromSeconds(batchIntervalInSeconds))
189+
: base(batchSizeLimit, TimeSpan.FromSeconds(batchIntervalInSeconds), queueLimit ?? NoQueueLimit)
177190
{
178191
_uriPath = uriPath;
179192
_splunkHost = splunkHost;

src/Serilog.Sinks.Splunk/SplunkLoggingConfigurationExtensions.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public static class SplunkLoggingConfigurationExtensions
4949
/// <param name="renderTemplate">If true, the message template will be rendered</param>
5050
/// <param name="batchIntervalInSeconds">The interval in seconds that the queue should be instpected for batching</param>
5151
/// <param name="batchSizeLimit">The size of the batch</param>
52+
/// <param name="queueLimit">Maximum number of events in the queue</param>
5253
/// <param name="messageHandler">The handler used to send HTTP requests</param>
5354
/// <param name="levelSwitch">A switch allowing the pass-through minimum level to be changed at runtime.</param>
5455
/// <returns></returns>
@@ -66,6 +67,7 @@ public static LoggerConfiguration EventCollector(
6667
bool renderTemplate = true,
6768
int batchIntervalInSeconds = 2,
6869
int batchSizeLimit = 100,
70+
int? queueLimit = null,
6971
HttpMessageHandler messageHandler = null,
7072
LoggingLevelSwitch levelSwitch = null)
7173
{
@@ -81,6 +83,7 @@ public static LoggerConfiguration EventCollector(
8183
index,
8284
batchIntervalInSeconds,
8385
batchSizeLimit,
86+
queueLimit,
8487
formatProvider,
8588
renderTemplate,
8689
messageHandler);
@@ -97,9 +100,10 @@ public static LoggerConfiguration EventCollector(
97100
/// <param name="jsonFormatter">The text formatter used to render log events into a JSON format for consumption by Splunk</param>
98101
/// <param name="uriPath">Change the default endpoint of the Event Collector e.g. services/collector/event</param>
99102
/// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
100-
103+
101104
/// <param name="batchIntervalInSeconds">The interval in seconds that the queue should be instpected for batching</param>
102105
/// <param name="batchSizeLimit">The size of the batch</param>
106+
/// <param name="queueLimit">Maximum number of events in the queue</param>
103107
/// <param name="messageHandler">The handler used to send HTTP requests</param>
104108
/// <param name="levelSwitch">A switch allowing the pass-through minimum level to be changed at runtime.</param>
105109
/// <returns></returns>
@@ -112,6 +116,7 @@ public static LoggerConfiguration EventCollector(
112116
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
113117
int batchIntervalInSeconds = 2,
114118
int batchSizeLimit = 100,
119+
int? queueLimit = null,
115120
HttpMessageHandler messageHandler = null,
116121
LoggingLevelSwitch levelSwitch = null)
117122
{
@@ -124,6 +129,7 @@ public static LoggerConfiguration EventCollector(
124129
uriPath,
125130
batchIntervalInSeconds,
126131
batchSizeLimit,
132+
queueLimit,
127133
jsonFormatter,
128134
messageHandler);
129135

@@ -147,6 +153,7 @@ public static LoggerConfiguration EventCollector(
147153
/// <param name="renderTemplate">If ture, the message template will be rendered</param>
148154
/// <param name="batchIntervalInSeconds">The interval in seconds that the queue should be instpected for batching</param>
149155
/// <param name="batchSizeLimit">The size of the batch</param>
156+
/// <param name="queueLimit">Maximum number of events in the queue</param>
150157
/// <param name="messageHandler">The handler used to send HTTP requests</param>
151158
/// <param name="levelSwitch">A switch allowing the pass-through minimum level to be changed at runtime.</param>
152159
/// <param name="fields">Customfields that will be indexed in splunk with this event</param>
@@ -166,6 +173,7 @@ public static LoggerConfiguration EventCollector(
166173
bool renderTemplate = true,
167174
int batchIntervalInSeconds = 2,
168175
int batchSizeLimit = 100,
176+
int? queueLimit = null,
169177
HttpMessageHandler messageHandler = null,
170178
LoggingLevelSwitch levelSwitch = null)
171179
{
@@ -182,6 +190,7 @@ public static LoggerConfiguration EventCollector(
182190
fields,
183191
batchIntervalInSeconds,
184192
batchSizeLimit,
193+
queueLimit,
185194
formatProvider,
186195
renderTemplate,
187196
messageHandler

0 commit comments

Comments
 (0)