Skip to content

Commit 7987c77

Browse files
committed
Exposed Batch size and interval
1 parent 74a1a6d commit 7987c77

File tree

7 files changed

+80
-93
lines changed

7 files changed

+80
-93
lines changed

sample/Serilog.Sinks.Splunk.Sample/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void Configure()
3434

3535
Log.Logger = new LoggerConfiguration()
3636
.WriteTo.LiterateConsole()
37-
.WriteTo.SplunkViaEventCollector("https://mysplunk:8088/services/collector", "685546AE-0278-4786-97C4-5971676D5D70")
37+
.WriteTo.SplunkViaEventCollector("https://mysplunk:8088/services/collector", "685546AE-0278-4786-97C4-5971676D5D70",renderTemplate:false)
3838
.Enrich.WithThreadId()
3939
.Enrich.WithProperty("SplunkSample", "ViaEventCollector")
4040
.MinimumLevel.Debug()

src/Serilog.Sinks.Splunk.FullNetFx/LoggerConfigurationSplunkExtensions.cs

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,43 +22,12 @@
2222
namespace Serilog
2323
{
2424
/// <summary>
25-
/// Adds the WriteTo.SplunkViaHttp() extension method to <see cref="LoggerConfiguration"/>.
25+
/// Adds the WriteTo.SplunkViaEventCollector() extension method to <see cref="LoggerConfiguration"/>.
2626
/// </summary>
2727
public static class LoggerConfigurationSplunkExtensions
2828
{
29-
30-
31-
internal const string DefaultOutputTemplate =
32-
"{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}";
33-
34-
/// <summary>
35-
///
36-
/// </summary>
37-
/// <param name="sinkConfiguration"></param>
38-
/// <param name="splunkHost"></param>
39-
/// <param name="eventCollectorToken"></param>
40-
/// <param name="restrictedToMinimumLevel"></param>
41-
/// <param name="outputTemplate"></param>
42-
/// <param name="formatProvider"></param>
43-
/// <param name="renderTemplate"></param>
44-
/// <returns></returns>
45-
public static LoggerConfiguration SplunkViaEventCollector(
46-
this LoggerSinkConfiguration sinkConfiguration,
47-
string splunkHost,
48-
string eventCollectorToken,
49-
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
50-
string outputTemplate = DefaultOutputTemplate,
51-
IFormatProvider formatProvider = null, bool renderTemplate = true)
52-
{
53-
if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration));
54-
if (outputTemplate == null) throw new ArgumentNullException(nameof(outputTemplate));
55-
var formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider);
56-
return sinkConfiguration.Sink(new EventCollectorSink(splunkHost, eventCollectorToken), restrictedToMinimumLevel);
57-
}
58-
59-
6029
/// <summary>
61-
/// Adds a sink that writes log events as to a Splunk instance via http.
30+
/// Adds a sink that writes log events as to a Splunk instance via UDP.
6231
/// </summary>
6332
/// <param name="loggerConfiguration">The logger config</param>
6433
/// <param name="host">The Splunk host that is configured for UDP logging</param>

src/Serilog.Sinks.Splunk.FullNetFx/Serilog.Sinks.Splunk.FullNetFx.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@
6262
<Reference Include="System.Net.Http" />
6363
</ItemGroup>
6464
<ItemGroup>
65+
<Compile Include="..\Serilog.Sinks.Splunk\LoggerConfigurationSplunkPCLExtensions.cs">
66+
<Link>LoggerConfigurationSplunkPCLExtensions.cs</Link>
67+
</Compile>
6568
<Compile Include="..\Serilog.Sinks.Splunk\Sinks\Splunk\EventCollectorExtensions.cs">
6669
<Link>Sinks\Splunk\EventCollectorExtensions.cs</Link>
6770
</Compile>

src/Serilog.Sinks.Splunk/LoggerConfigurationSplunkExtensions.cs

Lines changed: 0 additions & 57 deletions
This file was deleted.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright 2014 Serilog Contributors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using System;
16+
using Serilog.Configuration;
17+
using Serilog.Events;
18+
using Serilog.Formatting.Display;
19+
using Serilog.Sinks.Splunk;
20+
21+
namespace Serilog
22+
{
23+
/// <summary>
24+
/// Fluent extenstions for the Serilog configuration
25+
/// </summary>
26+
public static class LoggerConfigurationSplunkPCLExtensions
27+
{
28+
29+
internal const string DefaultOutputTemplate =
30+
"{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}";
31+
32+
/// <summary>
33+
/// Adds a sink that writes log events as to a Splunk instance via UDP.
34+
/// </summary>
35+
/// <param name="configuration">The logger config</param>
36+
/// <param name="splunkHost">The Splunk host that is configured with an Event Collector</param>
37+
/// <param name="eventCollectorToken">The token provided to authenticate to the Splunk Event Collector</param>
38+
/// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
39+
/// <param name="outputTemplate">The output template to be used when logging</param>
40+
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
41+
/// <param name="renderTemplate">If ture, the message template will be rendered</param>
42+
/// <param name="batchIntervalInSeconds">The interval in seconds that the queue should be instpected for batching</param>
43+
/// <param name="batchSizeLimit">The size of the batch</param>
44+
/// <returns></returns>
45+
public static LoggerConfiguration SplunkViaEventCollector(
46+
this LoggerSinkConfiguration configuration,
47+
string splunkHost,
48+
string eventCollectorToken,
49+
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
50+
string outputTemplate = DefaultOutputTemplate,
51+
IFormatProvider formatProvider = null,
52+
bool renderTemplate = true,
53+
int batchIntervalInSeconds = 2,
54+
int batchSizeLimit = 10)
55+
{
56+
if (configuration == null) throw new ArgumentNullException(nameof(configuration));
57+
if (outputTemplate == null) throw new ArgumentNullException(nameof(outputTemplate));
58+
59+
var eventCollectorSink = new EventCollectorSink(
60+
splunkHost,
61+
eventCollectorToken,
62+
batchIntervalInSeconds,
63+
batchSizeLimit,
64+
formatProvider,
65+
renderTemplate);
66+
67+
return configuration.Sink(eventCollectorSink, restrictedToMinimumLevel);
68+
}
69+
70+
71+
}
72+
}

src/Serilog.Sinks.Splunk/Serilog.Sinks.Splunk.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
<None Include="Serilog.Sinks.Splunk.nuspec" />
5050
</ItemGroup>
5151
<ItemGroup>
52-
<Compile Include="LoggerConfigurationSplunkExtensions.cs" />
52+
<Compile Include="LoggerConfigurationSplunkPCLExtensions.cs" />
5353
<Compile Include="Properties\AssemblyInfo.cs" />
5454
<Compile Include="..\..\assets\CommonAssemblyInfo.cs">
5555
<Link>Properties\CommonAssemblyInfo.cs</Link>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public class EventCollectorSink : ILogEventSink
8585
public EventCollectorSink(
8686
string splunkHost,
8787
string eventCollectorToken,
88-
int batchIntervalInSeconds = 10,
88+
int batchIntervalInSeconds = 2,
8989
int batchSizeLimit = 10,
9090
IFormatProvider formatProvider = null,
9191
bool renderTemplate = true

0 commit comments

Comments
 (0)