Skip to content

Commit 80b91cd

Browse files
merbladependabot[bot]EngRajabi
authored
3.7.0 Release (#150)
* 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>
1 parent e588096 commit 80b91cd

File tree

9 files changed

+114
-129
lines changed

9 files changed

+114
-129
lines changed

appveyor.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
version: '{build}'
22
skip_tags: true
33
image:
4-
- Visual Studio 2017
5-
- Ubuntu
4+
- Visual Studio 2019
5+
- Ubuntu2004
66
configuration:
77
- Release
88
build_script:
@@ -14,13 +14,13 @@ for:
1414
-
1515
matrix:
1616
only:
17-
- image: Ubuntu
17+
- image: Ubuntu2004
1818
build_script:
1919
- sh build.sh
2020
deploy:
2121
- provider: NuGet
2222
api_key:
23-
secure: K3/810hkTO6rd2AEHVkUQAadjGmDREus9k96QHu6hxrA1/wRTuAJemHMKtVVgIvf
23+
secure: gjQNjT9fJBA2Bx+TCFnO0SrgjMDe3Wa99Dj0M8ADwAXeT8LIU4ECqjlzvYsapCYK
2424
skip_symbols: true
2525
on:
2626
branch: /^(master|dev)$/

build.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ dotnet restore
55

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

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

16-
dotnet build -f netcoreapp2.0 -c Release sample/Sample/Sample.csproj
16+
dotnet build -f net5.0 -c Release sample/Sample/Sample.csproj

sample/Sample/Sample.csproj

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFrameworks>netcoreapp2.0</TargetFrameworks>
5+
<TargetFramework>net5.0</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Serilog" Version="2.6.0" />
10-
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.0" />
11-
<PackageReference Include="System.Net.Http" Version="4.3.3" />
12-
<PackageReference Include="Serilog.Settings.Configuration" Version="2.6.1" />
13-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.1" />
9+
<PackageReference Include="Serilog" Version="2.10.0" />
10+
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.0" />
11+
<PackageReference Include="Serilog.Settings.Configuration" Version="3.3.0" />
12+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
1413
</ItemGroup>
1514

1615
<ItemGroup>

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

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
<PropertyGroup>
44
<Description>The Splunk Sink for Serilog</Description>
5-
<VersionPrefix>3.6.0</VersionPrefix>
5+
<VersionPrefix>3.7.0</VersionPrefix>
66
<Authors>Matthew Erbs, Serilog Contributors</Authors>
7-
<TargetFrameworks>net45;netstandard1.1;netstandard2.0</TargetFrameworks>
7+
<TargetFrameworks>netstandard2.1;netstandard2.0</TargetFrameworks>
88
<GenerateDocumentationFile>true</GenerateDocumentationFile>
99
<AssemblyName>Serilog.Sinks.Splunk</AssemblyName>
1010
<PackageId>Serilog.Sinks.Splunk</PackageId>
1111
<PackageTags>serilog;splunk;logging;event;collector;hec</PackageTags>
12-
<PackageIconUrl>http://serilog.net/images/serilog-sink-nuget.png</PackageIconUrl>
12+
<icon>http://serilog.net/images/serilog-sink-nuget.png</icon>
1313
<PackageProjectUrl>https://github.com/serilog/serilog-sinks-splunk</PackageProjectUrl>
14-
<PackageLicenseUrl>http://www.apache.org/licenses/LICENSE-2.0</PackageLicenseUrl>
14+
<license>http://www.apache.org/licenses/LICENSE-2.0</license>
1515
<RepositoryUrl>https://github.com/serilog/serilog-sinks-splunk</RepositoryUrl>
1616
<RepositoryType>git</RepositoryType>
1717
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile>
@@ -20,29 +20,9 @@
2020
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
2121
</PropertyGroup>
2222

23-
<PropertyGroup Condition=" '$(TargetFramework)' == 'net45' ">
24-
<!-- Don't reference unused System assemblies -->
25-
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
26-
</PropertyGroup>
27-
28-
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.1' ">
29-
<!-- Don't reference the full NETStandard.Library -->
30-
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
31-
</PropertyGroup>
32-
33-
<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
34-
<Reference Include="System" />
35-
<Reference Include="System.Core" />
36-
<Reference Include="System.Net.Http" />
37-
</ItemGroup>
38-
39-
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.1' ">
40-
<PackageReference Include="System.Net.Http" Version="4.3.0" />
41-
</ItemGroup>
42-
4323
<ItemGroup>
44-
<PackageReference Include="Serilog" Version="2.6.0" />
45-
<PackageReference Include="Serilog.Sinks.PeriodicBatching" Version="2.1.1" />
24+
<PackageReference Include="Serilog" Version="2.10.0" />
25+
<PackageReference Include="Serilog.Sinks.PeriodicBatching" Version="2.3.0" />
4626
</ItemGroup>
4727

4828
</Project>

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

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,25 @@
22

33
<PropertyGroup>
44
<Description>The Splunk TCP Sink for Serilog</Description>
5-
<VersionPrefix>1.4.0</VersionPrefix>
5+
<VersionPrefix>1.5.0</VersionPrefix>
66
<Authors>Matthew Erbs, Serilog Contributors</Authors>
7-
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks>
7+
<TargetFrameworks>netstandard2.1;netstandard2.0</TargetFrameworks>
88
<GenerateDocumentationFile>true</GenerateDocumentationFile>
99
<AssemblyName>Serilog.Sinks.Splunk.TCP</AssemblyName>
1010
<PackageId>Serilog.Sinks.Splunk.TCP</PackageId>
1111
<PackageTags>serilog;splunk;logging;tcp</PackageTags>
12-
<PackageIconUrl>http://serilog.net/images/serilog-sink-nuget.png</PackageIconUrl>
12+
<icon>http://serilog.net/images/serilog-sink-nuget.png</icon>
1313
<PackageProjectUrl>https://github.com/serilog/serilog-sinks-splunk</PackageProjectUrl>
14-
<PackageLicenseUrl>http://www.apache.org/licenses/LICENSE-2.0</PackageLicenseUrl>
14+
<license>http://www.apache.org/licenses/LICENSE-2.0</license>
1515
<RepositoryUrl>https://github.com/serilog/serilog-sinks-splunk</RepositoryUrl>
1616
<RepositoryType>git</RepositoryType>
1717
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile>
1818
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
1919
<SignAssembly>true</SignAssembly>
2020
</PropertyGroup>
2121

22-
<PropertyGroup Condition=" '$(TargetFramework)' == 'net45' ">
23-
<!-- Don't reference unused System assemblies -->
24-
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
25-
</PropertyGroup>
26-
27-
<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
28-
<Reference Include="System" />
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-
3922
<ItemGroup>
40-
<PackageReference Include="Serilog.Sinks.Splunk" Version="3.3.0" />
23+
<PackageReference Include="Serilog.Sinks.Splunk" Version="3.6.0" />
24+
<PackageReference Include="Splunk.Logging.Common.Core" Version="1.0.0" />
4125
</ItemGroup>
4226
</Project>

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

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,24 @@
22

33
<PropertyGroup>
44
<Description>The Splunk UDP Sink for Serilog</Description>
5-
<VersionPrefix>1.4.0</VersionPrefix>
5+
<VersionPrefix>1.5.0</VersionPrefix>
66
<Authors>Matthew Erbs, Serilog Contributors</Authors>
7-
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks>
7+
<TargetFrameworks>netstandard2.1;netstandard2.0</TargetFrameworks>
88
<GenerateDocumentationFile>true</GenerateDocumentationFile>
99
<AssemblyName>Serilog.Sinks.Splunk.UDP</AssemblyName>
1010
<PackageId>Serilog.Sinks.Splunk.UDP</PackageId>
1111
<PackageTags>serilog;splunk;logging;udp</PackageTags>
12-
<PackageIconUrl>http://serilog.net/images/serilog-sink-nuget.png</PackageIconUrl>
12+
<icon>http://serilog.net/images/serilog-sink-nuget.png</icon>
1313
<PackageProjectUrl>https://github.com/serilog/serilog-sinks-splunk</PackageProjectUrl>
14-
<PackageLicenseUrl>http://www.apache.org/licenses/LICENSE-2.0</PackageLicenseUrl>
14+
<license>http://www.apache.org/licenses/LICENSE-2.0</license>
1515
<RepositoryUrl>https://github.com/serilog/serilog-sinks-splunk</RepositoryUrl>
1616
<RepositoryType>git</RepositoryType>
1717
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile>
1818
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
1919
<SignAssembly>true</SignAssembly>
2020
</PropertyGroup>
2121

22-
<PropertyGroup Condition=" '$(TargetFramework)' == 'net45' ">
23-
<!-- Don't reference unused System assemblies -->
24-
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
25-
</PropertyGroup>
26-
27-
<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
28-
<Reference Include="System" />
29-
<Reference Include="System.Core" />
30-
<Reference Include="System.Net.Http" />
31-
</ItemGroup>
32-
33-
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
34-
<PackageReference Include="System.Net.Http" Version="4.3.0" />
35-
</ItemGroup>
36-
3722
<ItemGroup>
38-
<PackageReference Include="Serilog.Sinks.Splunk" Version="3.3.0" />
23+
<PackageReference Include="Serilog.Sinks.Splunk" Version="3.6.0" />
3924
</ItemGroup>
4025
</Project>

src/Serilog.Sinks.UDP/Sinks/Splunk/SplunkUdpSinkConnectionInfo.cs

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

15+
using System;
1516
using System.Net;
1617

1718
namespace Serilog.Sinks.Splunk
@@ -22,6 +23,8 @@ namespace Serilog.Sinks.Splunk
2223
/// </summary>
2324
public class SplunkUdpSinkConnectionInfo
2425
{
26+
private int _queueSizeLimit;
27+
2528
/// <summary>
2629
/// Splunk host.
2730
/// </summary>
@@ -32,6 +35,33 @@ public class SplunkUdpSinkConnectionInfo
3235
/// </summary>
3336
public int Port { get; }
3437

38+
///<summary>
39+
/// The maximum number of events to post in a single batch. Defaults to: 100.
40+
/// </summary>
41+
public int BatchPostingLimit { get; set; } = 100;
42+
43+
44+
///<summary>
45+
/// The time to wait between checking for event batches. Defaults to 10 seconds.
46+
/// </summary>
47+
public TimeSpan Period { get; set; } = TimeSpan.FromSeconds(10);
48+
49+
50+
/// <summary>
51+
/// The maximum number of events that will be held in-memory while waiting to ship them to
52+
/// Splunk. Beyond this limit, events will be dropped. The default is 100,000. Has no effect on
53+
/// durable log shipping.
54+
/// </summary>
55+
public int QueueSizeLimit
56+
{
57+
get { return _queueSizeLimit; }
58+
set
59+
{
60+
if (value < 0)
61+
throw new ArgumentOutOfRangeException(nameof(QueueSizeLimit), "Queue size limit must be non-zero.");
62+
_queueSizeLimit = value;
63+
}
64+
}
3565
/// <summary>
3666
/// Creates an instance of <see cref="SplunkUdpSinkConnectionInfo"/> used
3767
/// for defining connection info for connecting using UDP against Splunk.

src/Serilog.Sinks.UDP/Sinks/Splunk/UdpSink.cs

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,23 @@
1616
using Serilog.Events;
1717
using Serilog.Formatting;
1818
using System;
19+
using System.Collections.Generic;
1920
using System.IO;
2021
using System.Net.Sockets;
2122
using System.Text;
23+
using System.Threading.Tasks;
24+
using Serilog.Sinks.PeriodicBatching;
2225

2326
namespace Serilog.Sinks.Splunk
2427
{
2528
/// <summary>
2629
/// A sink that logs to Splunk over UDP
2730
/// </summary>
28-
public class UdpSink : ILogEventSink, IDisposable
31+
public class UdpSink : PeriodicBatchingSink
2932
{
3033
private readonly SplunkUdpSinkConnectionInfo _connectionInfo;
3134
private readonly ITextFormatter _formatter;
3235
private Socket _socket;
33-
private bool disposedValue = false;
3436

3537
/// <summary>
3638
/// Creates an instance of the Splunk UDP Sink.
@@ -48,51 +50,15 @@ public UdpSink(SplunkUdpSinkConnectionInfo connectionInfo, IFormatProvider forma
4850
/// </summary>
4951
/// <param name="connectionInfo">Connection info used for connecting against Splunk.</param>
5052
/// <param name="formatter">Custom formatter to use if you e.g. do not want to use the JsonFormatter.</param>
51-
public UdpSink(SplunkUdpSinkConnectionInfo connectionInfo, ITextFormatter formatter)
53+
public UdpSink(SplunkUdpSinkConnectionInfo connectionInfo, ITextFormatter formatter)
54+
: base(connectionInfo.BatchPostingLimit, connectionInfo.Period, connectionInfo.QueueSizeLimit)
5255
{
5356
_connectionInfo = connectionInfo;
5457
_formatter = formatter;
5558
Connect();
5659
}
57-
58-
/// <inheritdoc/>
59-
protected virtual void Dispose(bool disposing)
60-
{
61-
if (!disposedValue)
62-
{
63-
if (disposing)
64-
{
65-
DisposeSocket();
66-
}
67-
68-
disposedValue = true;
69-
}
70-
}
71-
72-
/// <inheritdoc/>
73-
public void Dispose()
74-
{
75-
Dispose(true);
76-
}
77-
78-
/// <inheritdoc/>
79-
public void Emit(LogEvent logEvent)
80-
{
81-
byte[] data = Convert(logEvent);
82-
83-
try
84-
{
85-
_socket.Send(data);
86-
}
87-
catch (SocketException)
88-
{
89-
// Try to reconnect and log
90-
DisposeSocket();
91-
Connect();
92-
_socket.Send(data);
93-
}
94-
}
95-
60+
61+
9662
private byte[] Convert(LogEvent logEvent)
9763
{
9864
var sb = new StringBuilder();
@@ -107,13 +73,51 @@ private void Connect()
10773
_socket.Connect(_connectionInfo.Host, _connectionInfo.Port);
10874
}
10975

76+
77+
protected override void Dispose(bool disposing)
78+
{
79+
DisposeSocket();
80+
81+
base.Dispose(true);
82+
}
83+
11084
private void DisposeSocket()
11185
{
11286
_socket?.Close();
11387
_socket?.Dispose();
11488
_socket = null;
11589
}
11690

91+
/// <summary>
92+
/// Emit a batch of log events, running to completion synchronously.
93+
/// </summary>
94+
/// <param name="events">The events to emit.</param>
95+
/// <remarks>
96+
/// Override either <see cref="M:Serilog.Sinks.PeriodicBatching.PeriodicBatchingSink.EmitBatch(System.Collections.Generic.IEnumerable{Serilog.Events.LogEvent})" />
97+
/// or <see cref="M:Serilog.Sinks.PeriodicBatching.PeriodicBatchingSink.EmitBatchAsync(System.Collections.Generic.IEnumerable{Serilog.Events.LogEvent})" />,
98+
/// not both.
99+
/// </remarks>
100+
protected override async Task EmitBatchAsync(IEnumerable<LogEvent> events)
101+
{
102+
foreach (var logEvent in events)
103+
{
104+
byte[] data = Convert(logEvent);
105+
106+
try
107+
{
108+
_socket.Send(data);
109+
}
110+
catch (SocketException)
111+
{
112+
// Try to reconnect and log
113+
DisposeSocket();
114+
Connect();
115+
_socket.Send(data);
116+
}
117+
}
118+
}
119+
120+
117121
private static SplunkJsonFormatter CreateDefaultFormatter(IFormatProvider formatProvider, bool renderTemplate)
118122
{
119123
return new SplunkJsonFormatter(renderTemplate, formatProvider);

0 commit comments

Comments
 (0)