Skip to content

Commit

Permalink
Merge pull request #86 from nblumhardt/serilog-4
Browse files Browse the repository at this point in the history
Update to Serilog 4, use built-in batching support
  • Loading branch information
nblumhardt authored Jun 5, 2024
2 parents b0bc87e + d3cd1ba commit 4ec8720
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 461 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

A wrapper for Serilog sinks that asynchronously emits events in batches, useful when logging to a slow and/or remote target.

> [!IMPORTANT]
> Serilog 4.x and later versions support batching natively. New projects should use Serilog's `IBatchedLogEventSink` and
> `WriteTo.Sink(IBatchedLogEventSink)`, not this package which is now only maintained for compatibility reasons.
### Getting started

Sinks that, for performance reasons, need to emit events in batches, can be implemented using `PeriodicBatchingSink`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

<PropertyGroup>
<Description>Buffer batches of log events to be flushed asynchronously.</Description>
<VersionPrefix>4.1.2</VersionPrefix>
<VersionPrefix>5.0.0</VersionPrefix>
<Authors>Serilog Contributors</Authors>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">net462</TargetFrameworks>
<TargetFrameworks>$(TargetFrameworks);netstandard2.0;net6.0</TargetFrameworks>
<Authors>Serilog Contributors</Authors>
<!-- .NET Framework version targeting is frozen at these two TFMs. -->
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT'">net471;net462</TargetFrameworks>
<!-- Policy is to trim TFM-specific builds to `netstandard2.0`, `net6.0`,
all active LTS versions, and optionally the latest RTM version, when releasing new
major Serilog versions. -->
<TargetFrameworks>$(TargetFrameworks);net8.0;net6.0;netstandard2.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<RootNamespace>Serilog</RootNamespace>
<PackageTags>serilog;batching;timer</PackageTags>
Expand All @@ -21,16 +26,12 @@
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
<PropertyGroup Condition=" '$(TargetFramework)' == 'net6.0' or '$(TargetFramework)' == 'net8.0' ">
<DefineConstants>$(DefineConstants);FEATURE_ASYNCDISPOSABLE</DefineConstants>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'net462'">
<PackageReference Include="System.Threading.Channels" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog" Version="4.0.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
</ItemGroup>

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Serilog.Events;

namespace Serilog.Sinks.PeriodicBatching;

sealed class LegacyBatchedSinkAdapter: Core.IBatchedLogEventSink, IDisposable
#if FEATURE_ASYNCDISPOSABLE
, IAsyncDisposable
#endif
{
readonly IBatchedLogEventSink _inner;
readonly bool _dispose;

public LegacyBatchedSinkAdapter(IBatchedLogEventSink inner, bool dispose)
{
_inner = inner;
_dispose = dispose;
}

public Task EmitBatchAsync(IReadOnlyCollection<LogEvent> batch)
{
return _inner.EmitBatchAsync(batch);
}

public Task OnEmptyBatchAsync()
{
return _inner.OnEmptyBatchAsync();
}

public void Dispose()
{
if (!_dispose)
return;

(_inner as IDisposable)?.Dispose();
}

#if FEATURE_ASYNCDISPOSABLE
public async ValueTask DisposeAsync()
{
if (!_dispose)
return;

if (_inner is IAsyncDisposable asyncDisposable)
{
await asyncDisposable.DisposeAsync();
}
else
{
Dispose();
}
}
#endif
}
Loading

0 comments on commit 4ec8720

Please sign in to comment.