Skip to content

Commit e86e99f

Browse files
committed
General Cleanup
1 parent ae57d8b commit e86e99f

File tree

4 files changed

+43
-192
lines changed

4 files changed

+43
-192
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Net;
23
using Splunk.Client;
34

45

@@ -13,8 +14,9 @@ static void Main(string[] args)
1314
var tcp = new ViaTcp();
1415
var udp = new ViaUdp();
1516
var eventCollector = new ViaEventCollector();
16-
udp.Configure();
17-
tcp.Configure();
17+
eventCollector.Configure();
18+
//udp.Configure();
19+
//tcp.Configure();
1820

1921
Log.Information("Simulation running, press any key to exit.");
2022

@@ -28,9 +30,12 @@ class ViaEventCollector : IConfigure
2830
{
2931
public void Configure()
3032
{
31-
Log.Logger = new LoggerConfiguration()
33+
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
34+
35+
36+
Log.Logger = new LoggerConfiguration()
3237
.WriteTo.LiterateConsole()
33-
.WriteTo.SplunkViaEventCollector("https://mysplunk", "685546AE-0278-4786-97C4-5971676D5D70")
38+
.WriteTo.SplunkViaEventCollector("https://mysplunk:8088/services/collector", "685546AE-0278-4786-97C4-5971676D5D70")
3439
.Enrich.WithThreadId()
3540
.Enrich.WithProperty("SplunkSample", "ViaEventCollector")
3641
.MinimumLevel.Debug()

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,23 @@
6262
<Reference Include="System.Net.Http" />
6363
</ItemGroup>
6464
<ItemGroup>
65+
<Compile Include="..\Serilog.Sinks.Splunk\Sinks\Splunk\EventCollectorExtensions.cs">
66+
<Link>Sinks\Splunk\EventCollectorExtensions.cs</Link>
67+
</Compile>
68+
<Compile Include="..\Serilog.Sinks.Splunk\Sinks\Splunk\RepeatAction.cs">
69+
<Link>Sinks\Splunk\RepeatAction.cs</Link>
70+
</Compile>
6571
<Compile Include="..\Serilog.Sinks.Splunk\Sinks\Splunk\SplunkJsonFormatter.cs">
6672
<Link>Sinks\Splunk\SplunkJsonFormatter.cs</Link>
6773
</Compile>
74+
<Compile Include="..\Serilog.Sinks.Splunk\Sinks\Splunk\SplunkViaEventCollectorSink.cs">
75+
<Link>Sinks\Splunk\SplunkViaEventCollectorSink.cs</Link>
76+
</Compile>
6877
<Compile Include="Properties\AssemblyInfo.cs" />
6978
<Compile Include="..\..\assets\CommonAssemblyInfo.cs">
7079
<Link>Properties\CommonAssemblyInfo.cs</Link>
7180
</Compile>
7281
<Compile Include="LoggerConfigurationSplunkExtensions.cs" />
73-
<Compile Include="Sinks\Splunk\SplunkViaEventCollector.cs" />
7482
<Compile Include="Sinks\Splunk\SplunkViaTcpSink.cs" />
7583
<Compile Include="Sinks\Splunk\SplunkViaUdpSink.cs" />
7684
</ItemGroup>

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

Lines changed: 0 additions & 178 deletions
This file was deleted.

src/Serilog.Sinks.Splunk/Sinks/Splunk/SplunkViaEventCollectorSink.cs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,31 @@ public class SplunkViaEventCollectorSink : ILogEventSink
2121
{
2222
private string _splunkHost;
2323
private string _eventCollectorToken;
24-
private int _batchSizeLimit;
24+
private int _batchSizeLimitLimit;
2525
private JsonFormatter _jsonFormatter;
2626
private ConcurrentQueue<LogEvent> _queue;
27+
private TimeSpan _batchInterval;
28+
29+
30+
//public const int DefaultBatchInterval = 10 * 1000; // 10 seconds
31+
//public const int DefaultBatchSize = 10 * 1024; // 10KB
32+
//public const int DefaultBatchCount = 10;
33+
2734

2835
/// <summary>
2936
/// Creates a new instance of the sink
3037
/// </summary>
3138
/// <param name="splunkHost"></param>
3239
/// <param name="eventCollectorToken"></param>
40+
/// <param name="batchSizeLimit"></param>
3341
/// <param name="formatProvider"></param>
3442
/// <param name="renderTemplate"></param>
35-
public SplunkViaEventCollectorSink(string splunkHost,
43+
/// <param name="batchIntervalInSeconds"></param>
44+
public SplunkViaEventCollectorSink(
45+
string splunkHost,
3646
string eventCollectorToken,
47+
int batchIntervalInSeconds = 10,
48+
int batchSizeLimit = 10,
3749
IFormatProvider formatProvider = null,
3850
bool renderTemplate = true
3951
)
@@ -42,11 +54,11 @@ public SplunkViaEventCollectorSink(string splunkHost,
4254
_eventCollectorToken = eventCollectorToken;
4355
_queue = new ConcurrentQueue<LogEvent>();
4456

45-
_jsonFormatter = new JsonFormatter(renderMessage: true, formatProvider: formatProvider);
46-
_batchSizeLimit = 1;
47-
var batchInterval = TimeSpan.FromSeconds(5);
57+
_jsonFormatter = new SplunkJsonFormatter(renderMessage: true, formatProvider: formatProvider, renderTemplate:renderTemplate);
58+
_batchSizeLimitLimit = batchSizeLimit;
59+
_batchInterval = TimeSpan.FromSeconds(batchIntervalInSeconds);
4860

49-
RepeatAction.OnInterval(batchInterval, () => ProcessQueue().Wait(), new CancellationToken());
61+
RepeatAction.OnInterval(_batchInterval, () => ProcessQueue().Wait(), new CancellationToken());
5062
}
5163

5264
/// <summary>
@@ -70,7 +82,7 @@ private async Task ProcessQueue()
7082
var events = new Queue<LogEvent>();
7183
LogEvent next;
7284

73-
while (count < _batchSizeLimit && _queue.TryDequeue(out next))
85+
while (count < _batchSizeLimitLimit && _queue.TryDequeue(out next))
7486
{
7587
count++;
7688
events.Enqueue(next);
@@ -80,10 +92,14 @@ private async Task ProcessQueue()
8092
return;
8193

8294
var sw = new StringWriter();
95+
96+
//TODO: Check status code against defaults
97+
//TODO: Put items back in queue if matching use case
98+
//TODO: Change to use retry methods
8399

100+
84101
foreach (var logEvent in events)
85-
{
86-
102+
{
87103
_jsonFormatter.Format(logEvent, sw);
88104

89105
var logEventAsAString = sw.ToString();

0 commit comments

Comments
 (0)