Skip to content

Commit 92c6fe1

Browse files
authored
Merge pull request #33 from Wedvich/dev
Added parameter to override the default HTTP message handler
2 parents b51f21e + c2dc094 commit 92c6fe1

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using System.IO;
1919
using System.Linq;
2020
using System.Net;
21+
using System.Net.Http;
2122
using System.Threading;
2223
using System.Threading.Tasks;
2324
using Serilog.Core;
@@ -73,7 +74,7 @@ public EventCollectorSink(
7374
formatProvider,
7475
renderTemplate)
7576
{
76-
}
77+
}
7778

7879
/// <summary>
7980
/// Creates a new instance of the sink
@@ -89,6 +90,7 @@ public EventCollectorSink(
8990
/// <param name="source">The source of the event</param>
9091
/// <param name="sourceType">The source type of the event</param>
9192
/// <param name="host">The host of the event</param>
93+
/// <param name="messageHandler">The handler used to send HTTP requests</param>
9294
public EventCollectorSink(
9395
string splunkHost,
9496
string eventCollectorToken,
@@ -100,7 +102,8 @@ public EventCollectorSink(
100102
int batchIntervalInSeconds,
101103
int batchSizeLimit,
102104
IFormatProvider formatProvider = null,
103-
bool renderTemplate = true)
105+
bool renderTemplate = true,
106+
HttpMessageHandler messageHandler = null)
104107
{
105108
_uriPath = uriPath;
106109
_splunkHost = splunkHost;
@@ -109,7 +112,9 @@ public EventCollectorSink(
109112
_batchSizeLimitLimit = batchSizeLimit;
110113

111114
var batchInterval = TimeSpan.FromSeconds(batchIntervalInSeconds);
112-
_httpClient = new EventCollectorClient(eventCollectorToken);
115+
_httpClient = messageHandler != null
116+
? new EventCollectorClient(eventCollectorToken, messageHandler)
117+
: new EventCollectorClient(eventCollectorToken);
113118

114119
var cancellationToken = new CancellationToken();
115120

src/Serilog.Sinks.Splunk/SplunkLoggingConfigurationExtensions.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public static class SplunkLoggingConfigurationExtensions
5151
/// <param name="renderTemplate">If ture, the message template will be rendered</param>
5252
/// <param name="batchIntervalInSeconds">The interval in seconds that the queue should be instpected for batching</param>
5353
/// <param name="batchSizeLimit">The size of the batch</param>
54+
/// <param name="messageHandler">The handler used to send HTTP requests</param>
5455
/// <returns></returns>
5556
public static LoggerConfiguration EventCollector(
5657
this LoggerSinkConfiguration configuration,
@@ -66,7 +67,8 @@ public static LoggerConfiguration EventCollector(
6667
IFormatProvider formatProvider = null,
6768
bool renderTemplate = true,
6869
int batchIntervalInSeconds = 2,
69-
int batchSizeLimit = 100)
70+
int batchSizeLimit = 100,
71+
HttpMessageHandler messageHandler = null)
7072
{
7173
if (configuration == null) throw new ArgumentNullException(nameof(configuration));
7274
if (outputTemplate == null) throw new ArgumentNullException(nameof(outputTemplate));
@@ -82,7 +84,8 @@ public static LoggerConfiguration EventCollector(
8284
batchIntervalInSeconds,
8385
batchSizeLimit,
8486
formatProvider,
85-
renderTemplate);
87+
renderTemplate,
88+
messageHandler);
8689

8790
return configuration.Sink(eventCollectorSink, restrictedToMinimumLevel);
8891
}

0 commit comments

Comments
 (0)