Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added parameter to override the default HTTP message handler #33

Merged
merged 1 commit into from
Oct 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/Serilog.Sinks.Splunk/Sinks/Splunk/EventCollectorSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -73,7 +74,7 @@ public EventCollectorSink(
formatProvider,
renderTemplate)
{
}
}

/// <summary>
/// Creates a new instance of the sink
Expand All @@ -89,6 +90,7 @@ public EventCollectorSink(
/// <param name="source">The source of the event</param>
/// <param name="sourceType">The source type of the event</param>
/// <param name="host">The host of the event</param>
/// <param name="messageHandler">The handler used to send HTTP requests</param>
public EventCollectorSink(
string splunkHost,
string eventCollectorToken,
Expand All @@ -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;
Expand All @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public static class SplunkLoggingConfigurationExtensions
/// <param name="renderTemplate">If ture, the message template will be rendered</param>
/// <param name="batchIntervalInSeconds">The interval in seconds that the queue should be instpected for batching</param>
/// <param name="batchSizeLimit">The size of the batch</param>
/// <param name="messageHandler">The handler used to send HTTP requests</param>
/// <returns></returns>
public static LoggerConfiguration EventCollector(
this LoggerSinkConfiguration configuration,
Expand All @@ -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));
Expand All @@ -82,7 +84,8 @@ public static LoggerConfiguration EventCollector(
batchIntervalInSeconds,
batchSizeLimit,
formatProvider,
renderTemplate);
renderTemplate,
messageHandler);

return configuration.Sink(eventCollectorSink, restrictedToMinimumLevel);
}
Expand Down