diff --git a/src/Serilog.Sinks.Splunk/Sinks/Splunk/EventCollectorSink.cs b/src/Serilog.Sinks.Splunk/Sinks/Splunk/EventCollectorSink.cs index 761f0fa..1e86e19 100644 --- a/src/Serilog.Sinks.Splunk/Sinks/Splunk/EventCollectorSink.cs +++ b/src/Serilog.Sinks.Splunk/Sinks/Splunk/EventCollectorSink.cs @@ -18,6 +18,7 @@ using System.IO; using System.Linq; using System.Net; +using System.Net.Http; using System.Threading; using System.Threading.Tasks; using Serilog.Core; @@ -73,7 +74,7 @@ public EventCollectorSink( formatProvider, renderTemplate) { - } + } /// /// Creates a new instance of the sink @@ -89,6 +90,7 @@ public EventCollectorSink( /// The source of the event /// The source type of the event /// The host of the event + /// The handler used to send HTTP requests public EventCollectorSink( string splunkHost, string eventCollectorToken, @@ -100,7 +102,8 @@ public EventCollectorSink( int batchIntervalInSeconds, int batchSizeLimit, IFormatProvider formatProvider = null, - bool renderTemplate = true) + bool renderTemplate = true, + HttpMessageHandler messageHandler = null) { _uriPath = uriPath; _splunkHost = splunkHost; @@ -109,7 +112,9 @@ public EventCollectorSink( _batchSizeLimitLimit = batchSizeLimit; var batchInterval = TimeSpan.FromSeconds(batchIntervalInSeconds); - _httpClient = new EventCollectorClient(eventCollectorToken); + _httpClient = messageHandler != null + ? new EventCollectorClient(eventCollectorToken, messageHandler) + : new EventCollectorClient(eventCollectorToken); var cancellationToken = new CancellationToken(); diff --git a/src/Serilog.Sinks.Splunk/SplunkLoggingConfigurationExtensions.cs b/src/Serilog.Sinks.Splunk/SplunkLoggingConfigurationExtensions.cs index 3db143b..b14dec1 100644 --- a/src/Serilog.Sinks.Splunk/SplunkLoggingConfigurationExtensions.cs +++ b/src/Serilog.Sinks.Splunk/SplunkLoggingConfigurationExtensions.cs @@ -51,6 +51,7 @@ public static class SplunkLoggingConfigurationExtensions /// If ture, the message template will be rendered /// The interval in seconds that the queue should be instpected for batching /// The size of the batch + /// The handler used to send HTTP requests /// public static LoggerConfiguration EventCollector( this LoggerSinkConfiguration configuration, @@ -66,7 +67,8 @@ public static LoggerConfiguration EventCollector( IFormatProvider formatProvider = null, bool renderTemplate = true, int batchIntervalInSeconds = 2, - int batchSizeLimit = 100) + int batchSizeLimit = 100, + HttpMessageHandler messageHandler = null) { if (configuration == null) throw new ArgumentNullException(nameof(configuration)); if (outputTemplate == null) throw new ArgumentNullException(nameof(outputTemplate)); @@ -82,7 +84,8 @@ public static LoggerConfiguration EventCollector( batchIntervalInSeconds, batchSizeLimit, formatProvider, - renderTemplate); + renderTemplate, + messageHandler); return configuration.Sink(eventCollectorSink, restrictedToMinimumLevel); }