Skip to content

Commit

Permalink
Merge pull request #128 from serilog/dev
Browse files Browse the repository at this point in the history
3.4 Release
  • Loading branch information
merbla authored Jul 2, 2020
2 parents 0bc82f5 + efdda1f commit 01af224
Show file tree
Hide file tree
Showing 13 changed files with 326 additions and 422 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 3.4.0
- [#126](https://github.com/serilog/serilog-sinks-splunk/pull/126)
- [#122](https://github.com/serilog/serilog-sinks-splunk/pull/122)
- [#121](https://github.com/serilog/serilog-sinks-splunk/pull/121)

## 3.3.0
- Correct issues relating to #76 and signing.
- Bump version to 3.3 for core Sink.
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ for:
deploy:
- provider: NuGet
api_key:
secure: N59tiJECUYpip6tEn0xvdmDAEiP9SIzyLEFLpwiigm/8WhJvBNs13QxzT1/3/JW/
secure: K3/810hkTO6rd2AEHVkUQAadjGmDREus9k96QHu6hxrA1/wRTuAJemHMKtVVgIvf
skip_symbols: true
on:
branch: /^(master|dev)$/
Expand Down
2 changes: 1 addition & 1 deletion src/Serilog.Sinks.Splunk/Serilog.Sinks.Splunk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Description>The Splunk Sink for Serilog</Description>
<VersionPrefix>3.3.0</VersionPrefix>
<VersionPrefix>3.4.0</VersionPrefix>
<Authors>Matthew Erbs, Serilog Contributors</Authors>
<TargetFrameworks>net45;netstandard1.1;netstandard2.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down
16 changes: 14 additions & 2 deletions src/Serilog.Sinks.Splunk/Sinks/Splunk/EventCollectorClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,26 @@ namespace Serilog.Sinks.Splunk
{
internal class EventCollectorClient : HttpClient, IDisposable
{
private const string AUTH_SCHEME = "Splunk";
private const string SPLUNK_REQUEST_CHANNEL = "X-Splunk-Request-Channel";

public EventCollectorClient(string eventCollectorToken) : base()
{
DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Splunk", eventCollectorToken);
SetHeaders(eventCollectorToken);
}

public EventCollectorClient(string eventCollectorToken, HttpMessageHandler messageHandler) : base(messageHandler)
{
DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Splunk", eventCollectorToken);
SetHeaders(eventCollectorToken);
}

private void SetHeaders(string eventCollectorToken)
{
DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(AUTH_SCHEME, eventCollectorToken);
if (!this.DefaultRequestHeaders.Contains(SPLUNK_REQUEST_CHANNEL))
{
this.DefaultRequestHeaders.Add(SPLUNK_REQUEST_CHANNEL, Guid.NewGuid().ToString());
}
}
}
}
132 changes: 52 additions & 80 deletions src/Serilog.Sinks.Splunk/Sinks/Splunk/SplunkJsonFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using Serilog.Events;
using Serilog.Formatting;
using Serilog.Formatting.Json;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using Serilog.Events;
using Serilog.Formatting;
using Serilog.Formatting.Json;

namespace Serilog.Sinks.Splunk
{
Expand Down Expand Up @@ -63,38 +63,8 @@ public SplunkJsonFormatter(
string sourceType,
string host,
string index)
: this(renderTemplate, formatProvider, source, sourceType, host, index, null)
{
_renderTemplate = renderTemplate;
_formatProvider = formatProvider;

var suffixWriter = new StringWriter();
suffixWriter.Write("}"); // Terminates "event"

if (!string.IsNullOrWhiteSpace(source))
{
suffixWriter.Write(",\"source\":");
JsonValueFormatter.WriteQuotedJsonString(source, suffixWriter);
}

if (!string.IsNullOrWhiteSpace(sourceType))
{
suffixWriter.Write(",\"sourcetype\":");
JsonValueFormatter.WriteQuotedJsonString(sourceType, suffixWriter);
}

if (!string.IsNullOrWhiteSpace(host))
{
suffixWriter.Write(",\"host\":");
JsonValueFormatter.WriteQuotedJsonString(host, suffixWriter);
}

if (!string.IsNullOrWhiteSpace(index))
{
suffixWriter.Write(",\"index\":");
JsonValueFormatter.WriteQuotedJsonString(index, suffixWriter);
}
suffixWriter.Write('}'); // Terminates the payload
_suffix = suffixWriter.ToString();
}

/// <summary>
Expand All @@ -119,63 +89,65 @@ public SplunkJsonFormatter(
_renderTemplate = renderTemplate;
_formatProvider = formatProvider;

var suffixWriter = new StringWriter();
suffixWriter.Write("}"); // Terminates "event"

if (!string.IsNullOrWhiteSpace(source))
using (var suffixWriter = new StringWriter())
{
suffixWriter.Write(",\"source\":");
JsonValueFormatter.WriteQuotedJsonString(source, suffixWriter);
}
suffixWriter.Write("}"); // Terminates "event"

if (!string.IsNullOrWhiteSpace(sourceType))
{
suffixWriter.Write(",\"sourcetype\":");
JsonValueFormatter.WriteQuotedJsonString(sourceType, suffixWriter);
}
if (!string.IsNullOrWhiteSpace(source))
{
suffixWriter.Write(",\"source\":");
JsonValueFormatter.WriteQuotedJsonString(source, suffixWriter);
}

if (!string.IsNullOrWhiteSpace(host))
{
suffixWriter.Write(",\"host\":");
JsonValueFormatter.WriteQuotedJsonString(host, suffixWriter);
}
if (!string.IsNullOrWhiteSpace(sourceType))
{
suffixWriter.Write(",\"sourcetype\":");
JsonValueFormatter.WriteQuotedJsonString(sourceType, suffixWriter);
}

if (!string.IsNullOrWhiteSpace(index))
{
suffixWriter.Write(",\"index\":");
JsonValueFormatter.WriteQuotedJsonString(index, suffixWriter);
}
if (customFields != null)
{
// "fields": {"club":"glee", "wins",["regionals","nationals"]}
suffixWriter.Write(",\"fields\": {");
var lastFieldIndex = customFields.CustomFieldList.Count;
foreach (var customField in customFields.CustomFieldList)
if (!string.IsNullOrWhiteSpace(host))
{
if (customField.ValueList.Count == 1)
{
//only one value e.g "club":"glee",
suffixWriter.Write($"\"{customField.Name}\":");
suffixWriter.Write($"\"{customField.ValueList[0]}\"");
}
else
suffixWriter.Write(",\"host\":");
JsonValueFormatter.WriteQuotedJsonString(host, suffixWriter);
}

if (!string.IsNullOrWhiteSpace(index))
{
suffixWriter.Write(",\"index\":");
JsonValueFormatter.WriteQuotedJsonString(index, suffixWriter);
}
if (customFields != null)
{
// "fields": {"club":"glee", "wins",["regionals","nationals"]}
suffixWriter.Write(",\"fields\": {");
var lastFieldIndex = customFields.CustomFieldList.Count;
foreach (var customField in customFields.CustomFieldList)
{
//array of values e.g "wins",["regionals","nationals"]
suffixWriter.Write($"\"{customField.Name}\":[");
var lastArrIndex = customField.ValueList.Count;
foreach (var cf in customField.ValueList)
if (customField.ValueList.Count == 1)
{
suffixWriter.Write($"\"{cf}\"");
//Different behaviour if it is the last one
suffixWriter.Write(--lastArrIndex > 0 ? "," : "]");
//only one value e.g "club":"glee",
suffixWriter.Write($"\"{customField.Name}\":");
suffixWriter.Write($"\"{customField.ValueList[0]}\"");
}
else
{
//array of values e.g "wins",["regionals","nationals"]
suffixWriter.Write($"\"{customField.Name}\":[");
var lastArrIndex = customField.ValueList.Count;
foreach (var cf in customField.ValueList)
{
suffixWriter.Write($"\"{cf}\"");
//Different behaviour if it is the last one
suffixWriter.Write(--lastArrIndex > 0 ? "," : "]");
}
}
suffixWriter.Write(--lastFieldIndex > 0 ? "," : "}");
}
suffixWriter.Write(--lastFieldIndex > 0 ? "," : "}");

}

suffixWriter.Write('}'); // Terminates the payload
_suffix = suffixWriter.ToString();
}
suffixWriter.Write('}'); // Terminates the payload
_suffix = suffixWriter.ToString();
}

/// <inheritdoc/>
Expand Down
30 changes: 20 additions & 10 deletions src/Serilog.Sinks.TCP/Serilog.Sinks.Splunk.TCP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

<PropertyGroup>
<Description>The Splunk TCP Sink for Serilog</Description>
<VersionPrefix>1.2.0</VersionPrefix>
<VersionPrefix>1.4.0</VersionPrefix>
<Authors>Matthew Erbs, Serilog Contributors</Authors>
<TargetFrameworks>net45;</TargetFrameworks>
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>Serilog.Sinks.Splunk.TCP</AssemblyName>
<PackageId>Serilog.Sinks.Splunk.TCP</PackageId>
Expand All @@ -19,14 +19,24 @@
<SignAssembly>true</SignAssembly>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Serilog.Sinks.Splunk" Version="2.5.0" />
<PackageReference Include="Splunk.Logging.Common" Version="1.6.0" />
<Reference Include="System.Net.Http" />
<PropertyGroup Condition=" '$(TargetFramework)' == 'net45' ">
<!-- Don't reference unused System assemblies -->
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
<PackageReference Include="Serilog" Version="2.6.0" />
<PackageReference Include="Serilog.Sinks.PeriodicBatching" Version="2.1.1" />
<Reference Include="System.Core" />
<Reference Include="System.Net.Http" />
<PackageReference Include="Splunk.Logging.Common" Version="1.7.2" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<!--<PackageReference Include="System.Net.Http" Version="4.3.0" />-->
<PackageReference Include="Splunk.Logging.Common.Core" Version="1.0.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Serilog.Sinks.Splunk" Version="3.3.0" />
</ItemGroup>

</Project>
66 changes: 66 additions & 0 deletions src/Serilog.Sinks.TCP/Sinks/Splunk/SplunkTcpSinkConnectionInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright 2016 Serilog Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Net;

namespace Serilog.Sinks.Splunk
{
/// <summary>
/// Defines connection info used to connect against Splunk
/// using TCP.
/// </summary>
public class SplunkTcpSinkConnectionInfo
{
/// <summary>
/// Default size of the socket writer queue.
/// </summary>
public const int DefaultMaxQueueSize = 10000;

/// <summary>
/// Splunk host.
/// </summary>
public IPAddress Host { get; }

/// <summary>
/// Splunk port.
/// </summary>
public int Port { get; }

/// <summary>
/// Max Queue size for the TCP socket writer.
/// See <see cref="DefaultMaxQueueSize"/> for default value (10000).
/// </summary>
public int MaxQueueSize { get; set; } = DefaultMaxQueueSize;

/// <summary>
/// Creates an instance of <see cref="SplunkTcpSinkConnectionInfo"/> used
/// for defining connection info for connecting using TCP against Splunk.
/// </summary>
/// <param name="host">Splunk host.</param>
/// <param name="port">Splunk TCP port.</param>
public SplunkTcpSinkConnectionInfo(string host, int port) : this(IPAddress.Parse(host), port) { }

/// <summary>
/// Creates an instance of <see cref="SplunkTcpSinkConnectionInfo"/> used
/// for defining connection info for connecting using TCP against Splunk.
/// </summary>
/// <param name="host">Splunk host.</param>
/// <param name="port">Splunk TCP port.</param>
public SplunkTcpSinkConnectionInfo(IPAddress host, int port)
{
Host = host;
Port = port;
}
}
}
Loading

0 comments on commit 01af224

Please sign in to comment.