Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Serilog 4, drop PeriodicBatchingSink dependency #133

Merged
merged 1 commit into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
version: '{build}'
skip_tags: true
image: Visual Studio 2022
test: off
build_script:
- pwsh: ./Build.ps1
test: off
artifacts:
- path: artifacts/Serilog.*.nupkg
deploy:
- provider: NuGet
api_key:
secure: sDnchSg4TZIOK7oIUI6BJwFPNENTOZrGNsroGO1hehLJSvlHpFmpTwiX8+bgPD+Q
secure: ZpUO4ECx4c/V0Ecj04cfV1UGd+ZABeEG9DDW2fjG8vITjNYhmbiiJH0qNOnRy2G3
skip_symbols: true
on:
branch: /^(main|dev)$/
Expand All @@ -20,4 +20,3 @@ deploy:
tag: v$(appveyor_build_version)
on:
branch: main

13 changes: 5 additions & 8 deletions src/Serilog.Sinks.Email/LoggerConfigurationEmailExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
using Serilog.Events;
using Serilog.Formatting.Display;
using Serilog.Sinks.Email;
using Serilog.Sinks.PeriodicBatching;
// ReSharper disable MemberCanBePrivate.Global

namespace Serilog;
Expand All @@ -31,7 +30,7 @@ namespace Serilog;
/// </summary>
public static class LoggerConfigurationEmailExtensions
{
static readonly TimeSpan DefaultPeriod = TimeSpan.FromSeconds(30);
static readonly TimeSpan DefaultBufferingTimeLimit = TimeSpan.FromSeconds(30);
const int DefaultQueueLimit = 10000;

/// <summary>
Expand Down Expand Up @@ -120,27 +119,25 @@ public static LoggerConfiguration Email(
public static LoggerConfiguration Email(
this LoggerSinkConfiguration loggerConfiguration,
EmailSinkOptions options,
PeriodicBatchingSinkOptions? batchingOptions = null,
BatchingOptions? batchingOptions = null,
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
LoggingLevelSwitch? levelSwitch = null)
{
if (options == null) throw new ArgumentNullException(nameof(options));

batchingOptions ??= new PeriodicBatchingSinkOptions
batchingOptions ??= new BatchingOptions
{
// Batching not used by default: fire off an email immediately upon receiving each event.
BatchSizeLimit = 1,
Period = DefaultPeriod,
BufferingTimeLimit = DefaultBufferingTimeLimit,
EagerlyEmitFirstEvent = true,
QueueLimit = DefaultQueueLimit,
};

var transport = new MailKitEmailTransport(options);
var sink = new EmailSink(options, transport);

var batchingSink = new PeriodicBatchingSink(sink, batchingOptions);

return loggerConfiguration.Sink(batchingSink, restrictedToMinimumLevel, levelSwitch);
return loggerConfiguration.Sink(sink, batchingOptions, restrictedToMinimumLevel, levelSwitch);
}


Expand Down
9 changes: 4 additions & 5 deletions src/Serilog.Sinks.Email/Serilog.Sinks.Email.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<Description>Send Serilog events as SMTP email using MailKit.</Description>
<VersionPrefix>3.0.0</VersionPrefix>
<Authors>Serilog Contributors</Authors>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT'">net462</TargetFrameworks>
<TargetFrameworks>$(TargetFrameworks);netstandard2.0;net6.0</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT'">net462;net471</TargetFrameworks>
<TargetFrameworks>$(TargetFrameworks);netstandard2.0;net6.0;net8.0</TargetFrameworks>
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
Expand All @@ -30,9 +30,8 @@
<None Include="../../README.md" Pack="true" Visible="false" PackagePath="/" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<PackageReference Include="PolySharp" Version="1.14.1" PrivateAssets="All" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.PeriodicBatching" Version="4.0.0-*" />
<PackageReference Include="MailKit" Version="4.3.0" />
<PackageReference Include="Serilog" Version="4.0.0" />
<PackageReference Include="MailKit" Version="4.6.0" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions src/Serilog.Sinks.Email/Sinks/Email/EmailSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
using System.IO;
using System.Threading.Tasks;
using Serilog.Events;
using Serilog.Sinks.PeriodicBatching;
using System.Linq;
using Serilog.Core;

namespace Serilog.Sinks.Email;

Expand All @@ -41,7 +41,7 @@ public EmailSink(EmailSinkOptions options, IEmailTransport emailTransport)
/// Emit a batch of log events, running asynchronously.
/// </summary>
/// <param name="events">The events to emit.</param>
public Task EmitBatchAsync(IEnumerable<LogEvent> events)
public Task EmitBatchAsync(IReadOnlyCollection<LogEvent> events)
{
// ReSharper disable PossibleMultipleEnumeration

Expand Down
4 changes: 2 additions & 2 deletions test/Serilog.Sinks.Email.Tests/EmailSinkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Serilog.Configuration;
using Serilog.Sinks.Email.Tests.Support;
using Serilog.Sinks.PeriodicBatching;
using Xunit;
using Xunit.Abstractions;

Expand Down Expand Up @@ -140,7 +140,7 @@ public void WorksWithIBatchTextFormatter()
var sink = new EmailSink(emailConnectionInfo, emailTransport);

using (var emailLogger = new LoggerConfiguration()
.WriteTo.Sink(new PeriodicBatchingSink(sink, new PeriodicBatchingSinkOptions()))
.WriteTo.Sink(sink, new BatchingOptions())
.CreateLogger())
{
emailLogger.Information("Information");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.4" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down