Skip to content

Commit 01af224

Browse files
authored
Merge pull request #128 from serilog/dev
3.4 Release
2 parents 0bc82f5 + efdda1f commit 01af224

13 files changed

+326
-422
lines changed

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 3.4.0
2+
- [#126](https://github.com/serilog/serilog-sinks-splunk/pull/126)
3+
- [#122](https://github.com/serilog/serilog-sinks-splunk/pull/122)
4+
- [#121](https://github.com/serilog/serilog-sinks-splunk/pull/121)
5+
16
## 3.3.0
27
- Correct issues relating to #76 and signing.
38
- Bump version to 3.3 for core Sink.

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ for:
2020
deploy:
2121
- provider: NuGet
2222
api_key:
23-
secure: N59tiJECUYpip6tEn0xvdmDAEiP9SIzyLEFLpwiigm/8WhJvBNs13QxzT1/3/JW/
23+
secure: K3/810hkTO6rd2AEHVkUQAadjGmDREus9k96QHu6hxrA1/wRTuAJemHMKtVVgIvf
2424
skip_symbols: true
2525
on:
2626
branch: /^(master|dev)$/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<Description>The Splunk Sink for Serilog</Description>
5-
<VersionPrefix>3.3.0</VersionPrefix>
5+
<VersionPrefix>3.4.0</VersionPrefix>
66
<Authors>Matthew Erbs, Serilog Contributors</Authors>
77
<TargetFrameworks>net45;netstandard1.1;netstandard2.0</TargetFrameworks>
88
<GenerateDocumentationFile>true</GenerateDocumentationFile>

src/Serilog.Sinks.Splunk/Sinks/Splunk/EventCollectorClient.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,26 @@ namespace Serilog.Sinks.Splunk
2121
{
2222
internal class EventCollectorClient : HttpClient, IDisposable
2323
{
24+
private const string AUTH_SCHEME = "Splunk";
25+
private const string SPLUNK_REQUEST_CHANNEL = "X-Splunk-Request-Channel";
26+
2427
public EventCollectorClient(string eventCollectorToken) : base()
2528
{
26-
DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Splunk", eventCollectorToken);
29+
SetHeaders(eventCollectorToken);
2730
}
2831

2932
public EventCollectorClient(string eventCollectorToken, HttpMessageHandler messageHandler) : base(messageHandler)
3033
{
31-
DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Splunk", eventCollectorToken);
34+
SetHeaders(eventCollectorToken);
35+
}
36+
37+
private void SetHeaders(string eventCollectorToken)
38+
{
39+
DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(AUTH_SCHEME, eventCollectorToken);
40+
if (!this.DefaultRequestHeaders.Contains(SPLUNK_REQUEST_CHANNEL))
41+
{
42+
this.DefaultRequestHeaders.Add(SPLUNK_REQUEST_CHANNEL, Guid.NewGuid().ToString());
43+
}
3244
}
3345
}
3446
}

src/Serilog.Sinks.Splunk/Sinks/Splunk/SplunkJsonFormatter.cs

Lines changed: 52 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
using Serilog.Events;
16+
using Serilog.Formatting;
17+
using Serilog.Formatting.Json;
1518
using System;
1619
using System.Collections.Generic;
1720
using System.Globalization;
1821
using System.IO;
19-
using Serilog.Events;
20-
using Serilog.Formatting;
21-
using Serilog.Formatting.Json;
2222

2323
namespace Serilog.Sinks.Splunk
2424
{
@@ -63,38 +63,8 @@ public SplunkJsonFormatter(
6363
string sourceType,
6464
string host,
6565
string index)
66+
: this(renderTemplate, formatProvider, source, sourceType, host, index, null)
6667
{
67-
_renderTemplate = renderTemplate;
68-
_formatProvider = formatProvider;
69-
70-
var suffixWriter = new StringWriter();
71-
suffixWriter.Write("}"); // Terminates "event"
72-
73-
if (!string.IsNullOrWhiteSpace(source))
74-
{
75-
suffixWriter.Write(",\"source\":");
76-
JsonValueFormatter.WriteQuotedJsonString(source, suffixWriter);
77-
}
78-
79-
if (!string.IsNullOrWhiteSpace(sourceType))
80-
{
81-
suffixWriter.Write(",\"sourcetype\":");
82-
JsonValueFormatter.WriteQuotedJsonString(sourceType, suffixWriter);
83-
}
84-
85-
if (!string.IsNullOrWhiteSpace(host))
86-
{
87-
suffixWriter.Write(",\"host\":");
88-
JsonValueFormatter.WriteQuotedJsonString(host, suffixWriter);
89-
}
90-
91-
if (!string.IsNullOrWhiteSpace(index))
92-
{
93-
suffixWriter.Write(",\"index\":");
94-
JsonValueFormatter.WriteQuotedJsonString(index, suffixWriter);
95-
}
96-
suffixWriter.Write('}'); // Terminates the payload
97-
_suffix = suffixWriter.ToString();
9868
}
9969

10070
/// <summary>
@@ -119,63 +89,65 @@ public SplunkJsonFormatter(
11989
_renderTemplate = renderTemplate;
12090
_formatProvider = formatProvider;
12191

122-
var suffixWriter = new StringWriter();
123-
suffixWriter.Write("}"); // Terminates "event"
124-
125-
if (!string.IsNullOrWhiteSpace(source))
92+
using (var suffixWriter = new StringWriter())
12693
{
127-
suffixWriter.Write(",\"source\":");
128-
JsonValueFormatter.WriteQuotedJsonString(source, suffixWriter);
129-
}
94+
suffixWriter.Write("}"); // Terminates "event"
13095

131-
if (!string.IsNullOrWhiteSpace(sourceType))
132-
{
133-
suffixWriter.Write(",\"sourcetype\":");
134-
JsonValueFormatter.WriteQuotedJsonString(sourceType, suffixWriter);
135-
}
96+
if (!string.IsNullOrWhiteSpace(source))
97+
{
98+
suffixWriter.Write(",\"source\":");
99+
JsonValueFormatter.WriteQuotedJsonString(source, suffixWriter);
100+
}
136101

137-
if (!string.IsNullOrWhiteSpace(host))
138-
{
139-
suffixWriter.Write(",\"host\":");
140-
JsonValueFormatter.WriteQuotedJsonString(host, suffixWriter);
141-
}
102+
if (!string.IsNullOrWhiteSpace(sourceType))
103+
{
104+
suffixWriter.Write(",\"sourcetype\":");
105+
JsonValueFormatter.WriteQuotedJsonString(sourceType, suffixWriter);
106+
}
142107

143-
if (!string.IsNullOrWhiteSpace(index))
144-
{
145-
suffixWriter.Write(",\"index\":");
146-
JsonValueFormatter.WriteQuotedJsonString(index, suffixWriter);
147-
}
148-
if (customFields != null)
149-
{
150-
// "fields": {"club":"glee", "wins",["regionals","nationals"]}
151-
suffixWriter.Write(",\"fields\": {");
152-
var lastFieldIndex = customFields.CustomFieldList.Count;
153-
foreach (var customField in customFields.CustomFieldList)
108+
if (!string.IsNullOrWhiteSpace(host))
154109
{
155-
if (customField.ValueList.Count == 1)
156-
{
157-
//only one value e.g "club":"glee",
158-
suffixWriter.Write($"\"{customField.Name}\":");
159-
suffixWriter.Write($"\"{customField.ValueList[0]}\"");
160-
}
161-
else
110+
suffixWriter.Write(",\"host\":");
111+
JsonValueFormatter.WriteQuotedJsonString(host, suffixWriter);
112+
}
113+
114+
if (!string.IsNullOrWhiteSpace(index))
115+
{
116+
suffixWriter.Write(",\"index\":");
117+
JsonValueFormatter.WriteQuotedJsonString(index, suffixWriter);
118+
}
119+
if (customFields != null)
120+
{
121+
// "fields": {"club":"glee", "wins",["regionals","nationals"]}
122+
suffixWriter.Write(",\"fields\": {");
123+
var lastFieldIndex = customFields.CustomFieldList.Count;
124+
foreach (var customField in customFields.CustomFieldList)
162125
{
163-
//array of values e.g "wins",["regionals","nationals"]
164-
suffixWriter.Write($"\"{customField.Name}\":[");
165-
var lastArrIndex = customField.ValueList.Count;
166-
foreach (var cf in customField.ValueList)
126+
if (customField.ValueList.Count == 1)
167127
{
168-
suffixWriter.Write($"\"{cf}\"");
169-
//Different behaviour if it is the last one
170-
suffixWriter.Write(--lastArrIndex > 0 ? "," : "]");
128+
//only one value e.g "club":"glee",
129+
suffixWriter.Write($"\"{customField.Name}\":");
130+
suffixWriter.Write($"\"{customField.ValueList[0]}\"");
171131
}
132+
else
133+
{
134+
//array of values e.g "wins",["regionals","nationals"]
135+
suffixWriter.Write($"\"{customField.Name}\":[");
136+
var lastArrIndex = customField.ValueList.Count;
137+
foreach (var cf in customField.ValueList)
138+
{
139+
suffixWriter.Write($"\"{cf}\"");
140+
//Different behaviour if it is the last one
141+
suffixWriter.Write(--lastArrIndex > 0 ? "," : "]");
142+
}
143+
}
144+
suffixWriter.Write(--lastFieldIndex > 0 ? "," : "}");
172145
}
173-
suffixWriter.Write(--lastFieldIndex > 0 ? "," : "}");
146+
174147
}
175-
148+
suffixWriter.Write('}'); // Terminates the payload
149+
_suffix = suffixWriter.ToString();
176150
}
177-
suffixWriter.Write('}'); // Terminates the payload
178-
_suffix = suffixWriter.ToString();
179151
}
180152

181153
/// <inheritdoc/>

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

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
<PropertyGroup>
44
<Description>The Splunk TCP Sink for Serilog</Description>
5-
<VersionPrefix>1.2.0</VersionPrefix>
5+
<VersionPrefix>1.4.0</VersionPrefix>
66
<Authors>Matthew Erbs, Serilog Contributors</Authors>
7-
<TargetFrameworks>net45;</TargetFrameworks>
7+
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks>
88
<GenerateDocumentationFile>true</GenerateDocumentationFile>
99
<AssemblyName>Serilog.Sinks.Splunk.TCP</AssemblyName>
1010
<PackageId>Serilog.Sinks.Splunk.TCP</PackageId>
@@ -19,14 +19,24 @@
1919
<SignAssembly>true</SignAssembly>
2020
</PropertyGroup>
2121

22-
<ItemGroup>
23-
<PackageReference Include="Serilog.Sinks.Splunk" Version="2.5.0" />
24-
<PackageReference Include="Splunk.Logging.Common" Version="1.6.0" />
25-
<Reference Include="System.Net.Http" />
22+
<PropertyGroup Condition=" '$(TargetFramework)' == 'net45' ">
23+
<!-- Don't reference unused System assemblies -->
24+
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
25+
</PropertyGroup>
26+
27+
<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
2628
<Reference Include="System" />
27-
<Reference Include="Microsoft.CSharp" />
28-
<PackageReference Include="Serilog" Version="2.6.0" />
29-
<PackageReference Include="Serilog.Sinks.PeriodicBatching" Version="2.1.1" />
29+
<Reference Include="System.Core" />
30+
<Reference Include="System.Net.Http" />
31+
<PackageReference Include="Splunk.Logging.Common" Version="1.7.2" />
32+
</ItemGroup>
33+
34+
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
35+
<!--<PackageReference Include="System.Net.Http" Version="4.3.0" />-->
36+
<PackageReference Include="Splunk.Logging.Common.Core" Version="1.0.0" />
37+
</ItemGroup>
38+
39+
<ItemGroup>
40+
<PackageReference Include="Serilog.Sinks.Splunk" Version="3.3.0" />
3041
</ItemGroup>
31-
3242
</Project>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright 2016 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.Net;
16+
17+
namespace Serilog.Sinks.Splunk
18+
{
19+
/// <summary>
20+
/// Defines connection info used to connect against Splunk
21+
/// using TCP.
22+
/// </summary>
23+
public class SplunkTcpSinkConnectionInfo
24+
{
25+
/// <summary>
26+
/// Default size of the socket writer queue.
27+
/// </summary>
28+
public const int DefaultMaxQueueSize = 10000;
29+
30+
/// <summary>
31+
/// Splunk host.
32+
/// </summary>
33+
public IPAddress Host { get; }
34+
35+
/// <summary>
36+
/// Splunk port.
37+
/// </summary>
38+
public int Port { get; }
39+
40+
/// <summary>
41+
/// Max Queue size for the TCP socket writer.
42+
/// See <see cref="DefaultMaxQueueSize"/> for default value (10000).
43+
/// </summary>
44+
public int MaxQueueSize { get; set; } = DefaultMaxQueueSize;
45+
46+
/// <summary>
47+
/// Creates an instance of <see cref="SplunkTcpSinkConnectionInfo"/> used
48+
/// for defining connection info for connecting using TCP against Splunk.
49+
/// </summary>
50+
/// <param name="host">Splunk host.</param>
51+
/// <param name="port">Splunk TCP port.</param>
52+
public SplunkTcpSinkConnectionInfo(string host, int port) : this(IPAddress.Parse(host), port) { }
53+
54+
/// <summary>
55+
/// Creates an instance of <see cref="SplunkTcpSinkConnectionInfo"/> used
56+
/// for defining connection info for connecting using TCP against Splunk.
57+
/// </summary>
58+
/// <param name="host">Splunk host.</param>
59+
/// <param name="port">Splunk TCP port.</param>
60+
public SplunkTcpSinkConnectionInfo(IPAddress host, int port)
61+
{
62+
Host = host;
63+
Port = port;
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)