Skip to content

Commit

Permalink
3.7.0 Release (#150)
Browse files Browse the repository at this point in the history
* Bumps to System.Net.Http
* add default batch config 
* Update expired GitHub Key
* fix bug dispose (#153)

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Mohsen Rajabi <m.kabir8895@gmail.com>
  • Loading branch information
3 people authored Nov 7, 2021
1 parent e588096 commit 80b91cd
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 129 deletions.
8 changes: 4 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
version: '{build}'
skip_tags: true
image:
- Visual Studio 2017
- Ubuntu
- Visual Studio 2019
- Ubuntu2004
configuration:
- Release
build_script:
Expand All @@ -14,13 +14,13 @@ for:
-
matrix:
only:
- image: Ubuntu
- image: Ubuntu2004
build_script:
- sh build.sh
deploy:
- provider: NuGet
api_key:
secure: K3/810hkTO6rd2AEHVkUQAadjGmDREus9k96QHu6hxrA1/wRTuAJemHMKtVVgIvf
secure: gjQNjT9fJBA2Bx+TCFnO0SrgjMDe3Wa99Dj0M8ADwAXeT8LIU4ECqjlzvYsapCYK
skip_symbols: true
on:
branch: /^(master|dev)$/
Expand Down
6 changes: 3 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ dotnet restore

# Until # 65 is addressed build only core package. When available move to netstandard for all packages
for path in src/**/Serilog.Sinks.Splunk.csproj; do
dotnet build -f netstandard1.1 -c Release ${path}
dotnet build -f netstandard2.0 -c Release ${path}
dotnet build -f netstandard2.1 -c Release ${path}
done

for path in test/*.Tests/*.csproj; do
dotnet test -f netcoreapp2.0 -c Release ${path}
dotnet test -f net5.0 -c Release ${path}
done

dotnet build -f netcoreapp2.0 -c Release sample/Sample/Sample.csproj
dotnet build -f net5.0 -c Release sample/Sample/Sample.csproj
11 changes: 5 additions & 6 deletions sample/Sample/Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp2.0</TargetFrameworks>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Serilog" Version="2.6.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.0" />
<PackageReference Include="System.Net.Http" Version="4.3.3" />
<PackageReference Include="Serilog.Settings.Configuration" Version="2.6.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.1" />
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.3.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
32 changes: 6 additions & 26 deletions src/Serilog.Sinks.Splunk/Serilog.Sinks.Splunk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

<PropertyGroup>
<Description>The Splunk Sink for Serilog</Description>
<VersionPrefix>3.6.0</VersionPrefix>
<VersionPrefix>3.7.0</VersionPrefix>
<Authors>Matthew Erbs, Serilog Contributors</Authors>
<TargetFrameworks>net45;netstandard1.1;netstandard2.0</TargetFrameworks>
<TargetFrameworks>netstandard2.1;netstandard2.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>Serilog.Sinks.Splunk</AssemblyName>
<PackageId>Serilog.Sinks.Splunk</PackageId>
<PackageTags>serilog;splunk;logging;event;collector;hec</PackageTags>
<PackageIconUrl>http://serilog.net/images/serilog-sink-nuget.png</PackageIconUrl>
<icon>http://serilog.net/images/serilog-sink-nuget.png</icon>
<PackageProjectUrl>https://github.com/serilog/serilog-sinks-splunk</PackageProjectUrl>
<PackageLicenseUrl>http://www.apache.org/licenses/LICENSE-2.0</PackageLicenseUrl>
<license>http://www.apache.org/licenses/LICENSE-2.0</license>
<RepositoryUrl>https://github.com/serilog/serilog-sinks-splunk</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile>
Expand All @@ -20,29 +20,9 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net45' ">
<!-- Don't reference unused System assemblies -->
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.1' ">
<!-- Don't reference the full NETStandard.Library -->
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Net.Http" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.1' ">
<PackageReference Include="System.Net.Http" Version="4.3.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Serilog" Version="2.6.0" />
<PackageReference Include="Serilog.Sinks.PeriodicBatching" Version="2.1.1" />
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog.Sinks.PeriodicBatching" Version="2.3.0" />
</ItemGroup>

</Project>
28 changes: 6 additions & 22 deletions src/Serilog.Sinks.TCP/Serilog.Sinks.Splunk.TCP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,25 @@

<PropertyGroup>
<Description>The Splunk TCP Sink for Serilog</Description>
<VersionPrefix>1.4.0</VersionPrefix>
<VersionPrefix>1.5.0</VersionPrefix>
<Authors>Matthew Erbs, Serilog Contributors</Authors>
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks>
<TargetFrameworks>netstandard2.1;netstandard2.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>Serilog.Sinks.Splunk.TCP</AssemblyName>
<PackageId>Serilog.Sinks.Splunk.TCP</PackageId>
<PackageTags>serilog;splunk;logging;tcp</PackageTags>
<PackageIconUrl>http://serilog.net/images/serilog-sink-nuget.png</PackageIconUrl>
<icon>http://serilog.net/images/serilog-sink-nuget.png</icon>
<PackageProjectUrl>https://github.com/serilog/serilog-sinks-splunk</PackageProjectUrl>
<PackageLicenseUrl>http://www.apache.org/licenses/LICENSE-2.0</PackageLicenseUrl>
<license>http://www.apache.org/licenses/LICENSE-2.0</license>
<RepositoryUrl>https://github.com/serilog/serilog-sinks-splunk</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
<SignAssembly>true</SignAssembly>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net45' ">
<!-- Don't reference unused System assemblies -->
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
<Reference Include="System" />
<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" />
<PackageReference Include="Serilog.Sinks.Splunk" Version="3.6.0" />
<PackageReference Include="Splunk.Logging.Common.Core" Version="1.0.0" />
</ItemGroup>
</Project>
25 changes: 5 additions & 20 deletions src/Serilog.Sinks.UDP/Serilog.Sinks.Splunk.UDP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,24 @@

<PropertyGroup>
<Description>The Splunk UDP Sink for Serilog</Description>
<VersionPrefix>1.4.0</VersionPrefix>
<VersionPrefix>1.5.0</VersionPrefix>
<Authors>Matthew Erbs, Serilog Contributors</Authors>
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks>
<TargetFrameworks>netstandard2.1;netstandard2.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>Serilog.Sinks.Splunk.UDP</AssemblyName>
<PackageId>Serilog.Sinks.Splunk.UDP</PackageId>
<PackageTags>serilog;splunk;logging;udp</PackageTags>
<PackageIconUrl>http://serilog.net/images/serilog-sink-nuget.png</PackageIconUrl>
<icon>http://serilog.net/images/serilog-sink-nuget.png</icon>
<PackageProjectUrl>https://github.com/serilog/serilog-sinks-splunk</PackageProjectUrl>
<PackageLicenseUrl>http://www.apache.org/licenses/LICENSE-2.0</PackageLicenseUrl>
<license>http://www.apache.org/licenses/LICENSE-2.0</license>
<RepositoryUrl>https://github.com/serilog/serilog-sinks-splunk</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
<SignAssembly>true</SignAssembly>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net45' ">
<!-- Don't reference unused System assemblies -->
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Net.Http" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.Net.Http" Version="4.3.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Serilog.Sinks.Splunk" Version="3.3.0" />
<PackageReference Include="Serilog.Sinks.Splunk" Version="3.6.0" />
</ItemGroup>
</Project>
30 changes: 30 additions & 0 deletions src/Serilog.Sinks.UDP/Sinks/Splunk/SplunkUdpSinkConnectionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Net;

namespace Serilog.Sinks.Splunk
Expand All @@ -22,6 +23,8 @@ namespace Serilog.Sinks.Splunk
/// </summary>
public class SplunkUdpSinkConnectionInfo
{
private int _queueSizeLimit;

/// <summary>
/// Splunk host.
/// </summary>
Expand All @@ -32,6 +35,33 @@ public class SplunkUdpSinkConnectionInfo
/// </summary>
public int Port { get; }

///<summary>
/// The maximum number of events to post in a single batch. Defaults to: 100.
/// </summary>
public int BatchPostingLimit { get; set; } = 100;


///<summary>
/// The time to wait between checking for event batches. Defaults to 10 seconds.
/// </summary>
public TimeSpan Period { get; set; } = TimeSpan.FromSeconds(10);


/// <summary>
/// The maximum number of events that will be held in-memory while waiting to ship them to
/// Splunk. Beyond this limit, events will be dropped. The default is 100,000. Has no effect on
/// durable log shipping.
/// </summary>
public int QueueSizeLimit
{
get { return _queueSizeLimit; }
set
{
if (value < 0)
throw new ArgumentOutOfRangeException(nameof(QueueSizeLimit), "Queue size limit must be non-zero.");
_queueSizeLimit = value;
}
}
/// <summary>
/// Creates an instance of <see cref="SplunkUdpSinkConnectionInfo"/> used
/// for defining connection info for connecting using UDP against Splunk.
Expand Down
88 changes: 46 additions & 42 deletions src/Serilog.Sinks.UDP/Sinks/Splunk/UdpSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,23 @@
using Serilog.Events;
using Serilog.Formatting;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using Serilog.Sinks.PeriodicBatching;

namespace Serilog.Sinks.Splunk
{
/// <summary>
/// A sink that logs to Splunk over UDP
/// </summary>
public class UdpSink : ILogEventSink, IDisposable
public class UdpSink : PeriodicBatchingSink
{
private readonly SplunkUdpSinkConnectionInfo _connectionInfo;
private readonly ITextFormatter _formatter;
private Socket _socket;
private bool disposedValue = false;

/// <summary>
/// Creates an instance of the Splunk UDP Sink.
Expand All @@ -48,51 +50,15 @@ public UdpSink(SplunkUdpSinkConnectionInfo connectionInfo, IFormatProvider forma
/// </summary>
/// <param name="connectionInfo">Connection info used for connecting against Splunk.</param>
/// <param name="formatter">Custom formatter to use if you e.g. do not want to use the JsonFormatter.</param>
public UdpSink(SplunkUdpSinkConnectionInfo connectionInfo, ITextFormatter formatter)
public UdpSink(SplunkUdpSinkConnectionInfo connectionInfo, ITextFormatter formatter)
: base(connectionInfo.BatchPostingLimit, connectionInfo.Period, connectionInfo.QueueSizeLimit)
{
_connectionInfo = connectionInfo;
_formatter = formatter;
Connect();
}

/// <inheritdoc/>
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
DisposeSocket();
}

disposedValue = true;
}
}

/// <inheritdoc/>
public void Dispose()
{
Dispose(true);
}

/// <inheritdoc/>
public void Emit(LogEvent logEvent)
{
byte[] data = Convert(logEvent);

try
{
_socket.Send(data);
}
catch (SocketException)
{
// Try to reconnect and log
DisposeSocket();
Connect();
_socket.Send(data);
}
}



private byte[] Convert(LogEvent logEvent)
{
var sb = new StringBuilder();
Expand All @@ -107,13 +73,51 @@ private void Connect()
_socket.Connect(_connectionInfo.Host, _connectionInfo.Port);
}


protected override void Dispose(bool disposing)
{
DisposeSocket();

base.Dispose(true);
}

private void DisposeSocket()
{
_socket?.Close();
_socket?.Dispose();
_socket = null;
}

/// <summary>
/// Emit a batch of log events, running to completion synchronously.
/// </summary>
/// <param name="events">The events to emit.</param>
/// <remarks>
/// Override either <see cref="M:Serilog.Sinks.PeriodicBatching.PeriodicBatchingSink.EmitBatch(System.Collections.Generic.IEnumerable{Serilog.Events.LogEvent})" />
/// or <see cref="M:Serilog.Sinks.PeriodicBatching.PeriodicBatchingSink.EmitBatchAsync(System.Collections.Generic.IEnumerable{Serilog.Events.LogEvent})" />,
/// not both.
/// </remarks>
protected override async Task EmitBatchAsync(IEnumerable<LogEvent> events)
{
foreach (var logEvent in events)
{
byte[] data = Convert(logEvent);

try
{
_socket.Send(data);
}
catch (SocketException)
{
// Try to reconnect and log
DisposeSocket();
Connect();
_socket.Send(data);
}
}
}


private static SplunkJsonFormatter CreateDefaultFormatter(IFormatProvider formatProvider, bool renderTemplate)
{
return new SplunkJsonFormatter(renderTemplate, formatProvider);
Expand Down
Loading

0 comments on commit 80b91cd

Please sign in to comment.