Skip to content
This repository was archived by the owner on Jun 1, 2024. It is now read-only.

Commit 4b1c592

Browse files
authored
Update to Serilog.Sinks.PeriodicBatching v4.0 and break dependency on deprecated PeriodicBatchingSink inheritance API (#579)
1 parent 22fbaf9 commit 4b1c592

File tree

5 files changed

+42
-18
lines changed

5 files changed

+42
-18
lines changed

README.md

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

33
This repository contains two nuget packages: `Serilog.Sinks.Elasticsearch` and `Serilog.Formatting.Elasticsearch`.
44

5-
> __Just a heads up that the .NET team @elastic have created their own new Serilog Sink called Elastic.Serilog.Sinks (Package: https://www.nuget.org/packages/Elastic.Serilog.Sinks#readme-body-tab and documentation: https://www.elastic.co/guide/en/ecs-logging/dotnet/current/serilog-data-shipper.html). Althought this current sink will still work, I advice you to have a look first at the official Elastic implementation as it is better supported and more up to date.__
5+
> __Just a heads up that the .NET team @elastic have created their own new Serilog Sink called Elastic.Serilog.Sinks (Package: https://www.nuget.org/packages/Elastic.Serilog.Sinks#readme-body-tab and documentation: https://www.elastic.co/guide/en/ecs-logging/dotnet/current/serilog-data-shipper.html). Although this current sink will still work, I advise you to have a look first at the official Elastic implementation as it is better supported and more up to date.__
66
77
## Table of contents
88

sample/Serilog.Sinks.Elasticsearch.Sample/Serilog.Sinks.Elasticsearch.Sample.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0" />
1212
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="7.0.0" />
1313
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
14-
<PackageReference Include="Serilog" Version="2.12.0" />
14+
<PackageReference Include="Serilog" Version="3.1.1" />
1515
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
1616
</ItemGroup>
1717

serilog-sinks-elasticsearch.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Files", "Files", "{148431F6
1111
LICENSE = LICENSE
1212
nuget.config = nuget.config
1313
README.md = README.md
14+
GitVersion.yml = GitVersion.yml
1415
EndProjectSection
1516
EndProject
1617
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Sinks.Elasticsearch", "src\Serilog.Sinks.Elasticsearch\Serilog.Sinks.Elasticsearch.csproj", "{EEB0D119-687E-444E-BF14-9BDAEC9BA3EF}"

src/Serilog.Sinks.Elasticsearch/Serilog.Sinks.Elasticsearch.csproj

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
<Title>Serilog.Sinks.Elasticsearch</Title>
55
<Description>Serilog sink for Elasticsearch</Description>
66
<Copyright>Copyright © Serilog Contributors 2023</Copyright>
7-
</PropertyGroup>
8-
<PropertyGroup>
9-
<TargetFrameworks>netstandard2.0</TargetFrameworks>
7+
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
108
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
119
<LangVersion>latest</LangVersion>
1210
<GenerateDocumentationFile>true</GenerateDocumentationFile>
@@ -22,34 +20,35 @@
2220
<RepositoryUrl>https://github.com/serilog-contrib/serilog-sinks-elasticsearch</RepositoryUrl>
2321
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
2422
<RepositoryType>git</RepositoryType>
23+
<RootNamespace>Serilog</RootNamespace>
24+
<PackageReadmeFile>README.md</PackageReadmeFile>
2525
</PropertyGroup>
2626

2727
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
2828
<NoWarn>1591;1701;1702</NoWarn>
2929
<DefineConstants>$(DefineConstants);DURABLE;THREADING_TIMER</DefineConstants>
3030
</PropertyGroup>
3131

32+
<PropertyGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
33+
<NoWarn>1591;1701;1702</NoWarn>
34+
<DefineConstants>$(DefineConstants);DURABLE;THREADING_TIMER;ASYNC_DISPOSABLE</DefineConstants>
35+
</PropertyGroup>
3236

3337
<ItemGroup>
34-
3538
<ProjectReference Include="..\Serilog.Formatting.Elasticsearch\Serilog.Formatting.Elasticsearch.csproj" />
3639

37-
<PackageReference Include="Serilog" Version="2.12.0" />
38-
<PackageReference Include="Serilog.Formatting.Compact" Version="1.1.0" />
40+
<PackageReference Include="Serilog" Version="3.1.1" />
41+
<PackageReference Include="Serilog.Formatting.Compact" Version="2.0.0" />
3942
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
40-
<PackageReference Include="Serilog.Sinks.PeriodicBatching" Version="3.1.0" />
43+
<PackageReference Include="Serilog.Sinks.PeriodicBatching" Version="4.0.0" />
4144
<PackageReference Include="Elasticsearch.Net" Version="7.17.5" />
4245
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="7.0.2" />
43-
</ItemGroup>
4446

45-
<ItemGroup>
46-
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
47-
<_Parameter1>Serilog.Sinks.Elasticsearch.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100fb8d13fd344a1c6fe0fe83ef33c1080bf30690765bc6eb0df26ebfdf8f21670c64265b30db09f73a0dea5b3db4c9d18dbf6d5a25af5ce9016f281014d79dc3b4201ac646c451830fc7e61a2dfd633d34c39f87b81894191652df5ac63cc40c77f3542f702bda692e6e8a9158353df189007a49da0f3cfd55eb250066b19485ec</_Parameter1>
48-
</AssemblyAttribute>
49-
</ItemGroup>
47+
<InternalsVisibleTo Include="Serilog.Sinks.Elasticsearch.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100fb8d13fd344a1c6fe0fe83ef33c1080bf30690765bc6eb0df26ebfdf8f21670c64265b30db09f73a0dea5b3db4c9d18dbf6d5a25af5ce9016f281014d79dc3b4201ac646c451830fc7e61a2dfd633d34c39f87b81894191652df5ac63cc40c77f3542f702bda692e6e8a9158353df189007a49da0f3cfd55eb250066b19485ec" />
5048

51-
<ItemGroup>
5249
<None Include="..\..\assets\serilog-sink-nuget.png" Pack="true" Visible="false" PackagePath="" />
50+
<None Include="..\..\README.md" Pack="true" Visible="false" PackagePath="" />
51+
5352
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
5453
</ItemGroup>
5554

src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticSearchSink.cs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,20 @@
1919
using System.Runtime.Serialization;
2020
using System.Threading.Tasks;
2121
using Elasticsearch.Net;
22+
using Serilog.Core;
2223
using Serilog.Debugging;
2324
using Serilog.Events;
2425
using Serilog.Sinks.PeriodicBatching;
2526

2627
namespace Serilog.Sinks.Elasticsearch
2728
{
28-
public sealed class ElasticsearchSink : PeriodicBatchingSink
29+
public sealed class ElasticsearchSink : ILogEventSink, IDisposable
30+
#if ASYNC_DISPOSABLE
31+
, IAsyncDisposable
32+
#endif
2933
{
34+
readonly PeriodicBatchingSink _batchingSink;
35+
3036
public ElasticsearchSink(ElasticsearchSinkOptions options)
3137
: this(
3238
new BatchedElasticsearchSink(options),
@@ -42,10 +48,28 @@ public ElasticsearchSink(ElasticsearchSinkOptions options)
4248
}
4349

4450
private ElasticsearchSink(IBatchedLogEventSink batchedSink, PeriodicBatchingSinkOptions options)
45-
: base(batchedSink, options)
4651
{
52+
_batchingSink = new PeriodicBatchingSink(batchedSink, options);
53+
}
54+
55+
public void Dispose()
56+
{
57+
_batchingSink.Dispose();
58+
}
59+
60+
public void Emit(LogEvent logEvent)
61+
{
62+
_batchingSink.Emit(logEvent);
63+
}
64+
65+
#if ASYNC_DISPOSABLE
66+
public ValueTask DisposeAsync()
67+
{
68+
return _batchingSink.DisposeAsync();
4769
}
70+
#endif
4871
}
72+
4973
/// <summary>
5074
/// Writes log events as documents to ElasticSearch.
5175
/// </summary>

0 commit comments

Comments
 (0)