diff --git a/Build.ps1 b/Build.ps1 index 1694abc..07fcb2c 100644 --- a/Build.ps1 +++ b/Build.ps1 @@ -6,7 +6,7 @@ if(Test-Path .\artifacts) { Remove-Item .\artifacts -Force -Recurse } $branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL]; $revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL]; -$suffix = @{ $true = ""; $false = "$branch-$revision"}[$branch -eq "master" -and $revision -ne "local"] +$suffix = @{ $true = ""; $false = "$branch-$revision"}[$branch -eq "main" -and $revision -ne "local"] foreach ($src in ls src/Serilog.*) { Push-Location $src diff --git a/README.md b/README.md index 56bf721..85a6977 100644 --- a/README.md +++ b/README.md @@ -39,10 +39,10 @@ public static class LoggerSinkExampleConfiguration var batchingOptions = new PeriodicBatchingSinkOptions { - BatchSize = 100, + BatchSizeLimit = 100, Period = TimeSpan.FromSeconds(2), EagerlyEmitFirstEvent = true, - QueueSizeLimit = 10000 + QueueLimit = 10000 }; var batchingSink = new PeriodicBatchingSink(exampleSink, batchingOptions); diff --git a/appveyor.yml b/appveyor.yml index 03eb001..37b11c9 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,12 +1,6 @@ version: '{build}' skip_tags: true image: Visual Studio 2019 -install: - - ps: mkdir -Force ".\build\" | Out-Null - - ps: Invoke-WebRequest "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0/scripts/obtain/dotnet-install.ps1" -OutFile ".\build\installcli.ps1" - - ps: $env:DOTNET_INSTALL_DIR = "$pwd\.dotnetcli" - - ps: '& .\build\installcli.ps1 -InstallDir "$env:DOTNET_INSTALL_DIR" -NoPath -Version 1.0.1' - - ps: $env:Path = "$env:DOTNET_INSTALL_DIR;$env:Path" build_script: - ps: ./Build.ps1 test: off @@ -15,14 +9,14 @@ artifacts: deploy: - provider: NuGet api_key: - secure: N59tiJECUYpip6tEn0xvdmDAEiP9SIzyLEFLpwiigm/8WhJvBNs13QxzT1/3/JW/ + secure: rbdBqxBpLt4MkB+mrDOYNDOd8aVZ1zMkysaVNAXNKnC41FYifzX3l9LM8DCrUWU5 skip_symbols: true on: - branch: /^(master|dev)$/ + branch: /^(main|dev)$/ - provider: GitHub auth_token: secure: p4LpVhBKxGS5WqucHxFQ5c7C8cP74kbNB0Z8k9Oxx/PMaDQ1+ibmoexNqVU5ZlmX artifact: /Serilog.*\.nupkg/ tag: v$(appveyor_build_version) on: - branch: master + branch: main diff --git a/src/Serilog.Sinks.PeriodicBatching/Serilog.Sinks.PeriodicBatching.csproj b/src/Serilog.Sinks.PeriodicBatching/Serilog.Sinks.PeriodicBatching.csproj index feeaf68..601b6c0 100644 --- a/src/Serilog.Sinks.PeriodicBatching/Serilog.Sinks.PeriodicBatching.csproj +++ b/src/Serilog.Sinks.PeriodicBatching/Serilog.Sinks.PeriodicBatching.csproj @@ -2,9 +2,9 @@ The periodic batching sink for Serilog - 2.3.0 + 2.3.1 Serilog Contributors - net45;netstandard1.1;netstandard1.2;netstandard2.0 + net45;netstandard1.1;netstandard1.2;netstandard2.0;netstandard2.1 true Serilog.Sinks.PeriodicBatching Serilog @@ -19,8 +19,6 @@ https://github.com/serilog/serilog-sinks-periodicbatching git false - - true @@ -32,32 +30,12 @@ - - - - - - - - - - - - - - - - $(DefineConstants);THREADING_TIMER - - $(DefineConstants);THREADING_TIMER - - - $(DefineConstants);THREADING_TIMER + + + $(DefineConstants);THREADING_TIMER;EXECUTION_CONTEXT - - - + diff --git a/src/Serilog.Sinks.PeriodicBatching/Sinks/PeriodicBatching/BoundedConcurrentQueue.cs b/src/Serilog.Sinks.PeriodicBatching/Sinks/PeriodicBatching/BoundedConcurrentQueue.cs index 94e9ad4..2cb02fc 100644 --- a/src/Serilog.Sinks.PeriodicBatching/Sinks/PeriodicBatching/BoundedConcurrentQueue.cs +++ b/src/Serilog.Sinks.PeriodicBatching/Sinks/PeriodicBatching/BoundedConcurrentQueue.cs @@ -20,7 +20,7 @@ namespace Serilog.Sinks.PeriodicBatching { class BoundedConcurrentQueue { - public const int Unbounded = -1; + const int Unbounded = -1; readonly ConcurrentQueue _queue = new ConcurrentQueue(); readonly int _queueLimit; diff --git a/src/Serilog.Sinks.PeriodicBatching/Sinks/PeriodicBatching/PeriodicBatchingSink.cs b/src/Serilog.Sinks.PeriodicBatching/Sinks/PeriodicBatching/PeriodicBatchingSink.cs index 40b032b..78fefd7 100644 --- a/src/Serilog.Sinks.PeriodicBatching/Sinks/PeriodicBatching/PeriodicBatchingSink.cs +++ b/src/Serilog.Sinks.PeriodicBatching/Sinks/PeriodicBatching/PeriodicBatchingSink.cs @@ -37,9 +37,10 @@ namespace Serilog.Sinks.PeriodicBatching public class PeriodicBatchingSink : ILogEventSink, IDisposable, IBatchedLogEventSink { /// - /// Constant used to indicate that the internal queue shouldn't be limited. + /// Constant used with legacy constructor to indicate that the internal queue shouldn't be limited. /// - public const int NoQueueLimit = BoundedConcurrentQueue.Unbounded; + [Obsolete("Implement `IBatchedLogEventSink` and use the `PeriodicBatchingSinkOptions` constructor.")] + public const int NoQueueLimit = -1; readonly IBatchedLogEventSink _batchedLogEventSink; readonly int _batchSizeLimit; @@ -76,6 +77,7 @@ public PeriodicBatchingSink(IBatchedLogEventSink batchedSink, PeriodicBatchingSi /// /// The maximum number of events to include in a single batch. /// The time to wait between checking for event batches. + [Obsolete("Implement `IBatchedLogEventSink` and use the `PeriodicBatchingSinkOptions` constructor.")] protected PeriodicBatchingSink(int batchSizeLimit, TimeSpan period) : this(new PeriodicBatchingSinkOptions { @@ -97,13 +99,14 @@ protected PeriodicBatchingSink(int batchSizeLimit, TimeSpan period) /// The maximum number of events to include in a single batch. /// The time to wait between checking for event batches. /// Maximum number of events in the queue - use for an unbounded queue. + [Obsolete("Implement `IBatchedLogEventSink` and use the `PeriodicBatchingSinkOptions` constructor.")] protected PeriodicBatchingSink(int batchSizeLimit, TimeSpan period, int queueLimit) : this(new PeriodicBatchingSinkOptions { BatchSizeLimit = batchSizeLimit, Period = period, EagerlyEmitFirstEvent = true, - QueueLimit = queueLimit + QueueLimit = queueLimit == NoQueueLimit ? (int?)null : queueLimit }) { _batchedLogEventSink = this; @@ -199,6 +202,7 @@ protected virtual void EmitBatch(IEnumerable events) protected virtual async Task EmitBatchAsync(IEnumerable events) #pragma warning restore 1998 { + // ReSharper disable once MethodHasAsyncOverload EmitBatch(events); } @@ -337,6 +341,7 @@ protected virtual void OnEmptyBatch() protected virtual async Task OnEmptyBatchAsync() #pragma warning restore 1998 { + // ReSharper disable once MethodHasAsyncOverload OnEmptyBatch(); } diff --git a/src/Serilog.Sinks.PeriodicBatching/Sinks/PeriodicBatching/PeriodicBatchingSinkOptions.cs b/src/Serilog.Sinks.PeriodicBatching/Sinks/PeriodicBatching/PeriodicBatchingSinkOptions.cs index d0a8fbc..4bec61d 100644 --- a/src/Serilog.Sinks.PeriodicBatching/Sinks/PeriodicBatching/PeriodicBatchingSinkOptions.cs +++ b/src/Serilog.Sinks.PeriodicBatching/Sinks/PeriodicBatching/PeriodicBatchingSinkOptions.cs @@ -40,8 +40,8 @@ public class PeriodicBatchingSinkOptions /// /// Maximum number of events to hold in the sink's internal queue, or null - /// for an unbounded queue. The default is 10000. + /// for an unbounded queue. The default is 100000. /// public int? QueueLimit { get; set; } = 100000; } -} \ No newline at end of file +} diff --git a/src/Serilog.Sinks.PeriodicBatching/Sinks/PeriodicBatching/PortableTimer.cs b/src/Serilog.Sinks.PeriodicBatching/Sinks/PeriodicBatching/PortableTimer.cs index 7b5eb29..2752465 100644 --- a/src/Serilog.Sinks.PeriodicBatching/Sinks/PeriodicBatching/PortableTimer.cs +++ b/src/Serilog.Sinks.PeriodicBatching/Sinks/PeriodicBatching/PortableTimer.cs @@ -40,7 +40,10 @@ public PortableTimer(Func onTick) _onTick = onTick; #if THREADING_TIMER - _timer = new Timer(_ => OnTick(), null, Timeout.Infinite, Timeout.Infinite); +#if EXECUTION_CONTEXT + using (ExecutionContext.SuppressFlow()) +#endif + _timer = new Timer(_ => OnTick(), null, Timeout.Infinite, Timeout.Infinite); #endif } @@ -88,7 +91,7 @@ async void OnTick() { return; } - } + } _running = true; } @@ -115,7 +118,7 @@ async void OnTick() public void Dispose() { _cancel.Cancel(); - + lock (_stateLock) { if (_disposed) diff --git a/test/Serilog.Sinks.PeriodicBatching.Tests/PeriodicBatchingSinkTests.cs b/test/Serilog.Sinks.PeriodicBatching.Tests/PeriodicBatchingSinkTests.cs index 6f19975..a514e8f 100644 --- a/test/Serilog.Sinks.PeriodicBatching.Tests/PeriodicBatchingSinkTests.cs +++ b/test/Serilog.Sinks.PeriodicBatching.Tests/PeriodicBatchingSinkTests.cs @@ -60,6 +60,16 @@ public void Dispose() } } + class NullBatchedSink : PeriodicBatchingSink + { + public NullBatchedSink(int batchSizeLimit, TimeSpan period, int queueLimit) +#pragma warning disable 618 + : base(batchSizeLimit, period, queueLimit) +#pragma warning restore 618 + { + } + } + public class PeriodicBatchingSinkTests { static readonly TimeSpan TinyWait = TimeSpan.FromMilliseconds(200); @@ -112,5 +122,13 @@ public void WhenAnEventIsEnqueuedItIsWrittenToABatch_FlushWhileRunning() Assert.True(bs.IsDisposed); Assert.False(bs.WasCalledAfterDisposal); } + + [Fact] + public void SubclassesCanBeConstructedUsingNoQueueLimitConstant() + { +#pragma warning disable 618 + var _ = new NullBatchedSink(batchSizeLimit: 100, TimeSpan.FromSeconds(2), queueLimit: PeriodicBatchingSink.NoQueueLimit); +#pragma warning restore 618 + } } }