Skip to content

Commit

Permalink
Merge pull request #44 from serilog/dev
Browse files Browse the repository at this point in the history
Release 2.1.2
  • Loading branch information
merbla authored Jan 28, 2017
2 parents cf4f649 + b42da79 commit 95baa54
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 7 deletions.
5 changes: 4 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
##2.1.2
- [#43](https://github.com/serilog/serilog-sinks-splunk/pull/43) - Extend sink & static configuration to allow for custom JSON formatter.

##2.1.1
- [#38](https://github.com/serilog/serilog-sinks-splunk/issues/38)
- [#38](https://github.com/serilog/serilog-sinks-splunk/issues/38) - Fix for HttpEventlogCollector and sourceType
- Clean up of sample app using examples of host, sourcetype, source override

##2.1.0
Expand Down
2 changes: 1 addition & 1 deletion sample/project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.1.1",
"version": "2.1.2",
"buildOptions": {
"emitEntryPoint": true
},
Expand Down
39 changes: 35 additions & 4 deletions src/Serilog.Sinks.Splunk/Sinks/Splunk/EventCollectorSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using Serilog.Core;
using Serilog.Debugging;
using Serilog.Events;
using Serilog.Formatting;

namespace Serilog.Sinks.Splunk
{
Expand All @@ -35,7 +36,7 @@ public class EventCollectorSink : ILogEventSink, IDisposable
private readonly string _splunkHost;
private readonly string _uriPath;
private readonly int _batchSizeLimitLimit;
private readonly SplunkJsonFormatter _jsonFormatter;
private readonly ITextFormatter _jsonFormatter;
private readonly ConcurrentQueue<LogEvent> _queue;
private readonly EventCollectorClient _httpClient;

Expand Down Expand Up @@ -68,8 +69,8 @@ public EventCollectorSink(
: this(
splunkHost,
eventCollectorToken,
null, null, null, null, null,
batchIntervalInSeconds,
null, null, null, null, null,
batchIntervalInSeconds,
batchSizeLimit,
formatProvider,
renderTemplate)
Expand Down Expand Up @@ -104,11 +105,41 @@ public EventCollectorSink(
IFormatProvider formatProvider = null,
bool renderTemplate = true,
HttpMessageHandler messageHandler = null)
: this(
splunkHost,
eventCollectorToken,
uriPath,
batchIntervalInSeconds,
batchSizeLimit,
new SplunkJsonFormatter(renderTemplate, formatProvider, source, sourceType, host, index),
messageHandler)
{
}


/// <summary>
/// Creates a new instance of the sink
/// </summary>
/// <param name="splunkHost">The host of the Splunk instance with the Event collector configured</param>
/// <param name="eventCollectorToken">The token to use when authenticating with the event collector</param>
/// <param name="uriPath">Change the default endpoint of the Event Collector e.g. services/collector/event</param>
/// <param name="batchSizeLimit">The size of the batch when sending to the event collector</param>
/// <param name="batchIntervalInSeconds">The interval in seconds that batching should occur</param>
/// <param name="jsonFormatter">The text formatter used to render log events into a JSON format for consumption by Splunk</param>
/// <param name="messageHandler">The handler used to send HTTP requests</param>
public EventCollectorSink(
string splunkHost,
string eventCollectorToken,
string uriPath,
int batchIntervalInSeconds,
int batchSizeLimit,
ITextFormatter jsonFormatter,
HttpMessageHandler messageHandler = null)
{
_uriPath = uriPath;
_splunkHost = splunkHost;
_queue = new ConcurrentQueue<LogEvent>();
_jsonFormatter = new SplunkJsonFormatter(renderTemplate, formatProvider, source, sourceType, host, index);
_jsonFormatter = jsonFormatter;
_batchSizeLimitLimit = batchSizeLimit;

var batchInterval = TimeSpan.FromSeconds(batchIntervalInSeconds);
Expand Down
43 changes: 43 additions & 0 deletions src/Serilog.Sinks.Splunk/SplunkLoggingConfigurationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System.Net.Http;
using Serilog.Configuration;
using Serilog.Events;
using Serilog.Formatting;
using Serilog.Sinks.Splunk;

namespace Serilog
Expand Down Expand Up @@ -89,5 +90,47 @@ public static LoggerConfiguration EventCollector(

return configuration.Sink(eventCollectorSink, restrictedToMinimumLevel);
}

/// <summary>
/// Adds a sink that writes log events as to a Splunk instance via the HTTP Event Collector.
/// </summary>
/// <param name="configuration">The logger config</param>
/// <param name="splunkHost">The Splunk host that is configured with an Event Collector</param>
/// <param name="eventCollectorToken">The token provided to authenticate to the Splunk Event Collector</param>
/// <param name="jsonFormatter">The text formatter used to render log events into a JSON format for consumption by Splunk</param>
/// <param name="uriPath">Change the default endpoint of the Event Collector e.g. services/collector/event</param>
/// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
/// <param name="outputTemplate">The output template to be used when logging</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,
string splunkHost,
string eventCollectorToken,
ITextFormatter jsonFormatter,
string uriPath = "services/collector",
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
string outputTemplate = DefaultOutputTemplate,
int batchIntervalInSeconds = 2,
int batchSizeLimit = 100,
HttpMessageHandler messageHandler = null)
{
if (configuration == null) throw new ArgumentNullException(nameof(configuration));
if (jsonFormatter == null) throw new ArgumentNullException(nameof(jsonFormatter));
if (outputTemplate == null) throw new ArgumentNullException(nameof(outputTemplate));

var eventCollectorSink = new EventCollectorSink(
splunkHost,
eventCollectorToken,
uriPath,
batchIntervalInSeconds,
batchSizeLimit,
jsonFormatter,
messageHandler);

return configuration.Sink(eventCollectorSink, restrictedToMinimumLevel);
}
}
}
2 changes: 1 addition & 1 deletion src/Serilog.Sinks.Splunk/project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.1.1-*",
"version": "2.1.2-*",
"description": "The Splunk Sink for Serilog",
"authors": [
"Matthew Erbs, Serilog Contributors"
Expand Down

0 comments on commit 95baa54

Please sign in to comment.