Skip to content

Commit

Permalink
Merge pull request #48 from serilog/dev
Browse files Browse the repository at this point in the history
2.3.1 Release
  • Loading branch information
nblumhardt authored Jan 7, 2022
2 parents 6f3908f + af4c706 commit 3d73c17
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 49 deletions.
2 changes: 1 addition & 1 deletion Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 3 additions & 9 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

<PropertyGroup>
<Description>The periodic batching sink for Serilog</Description>
<VersionPrefix>2.3.0</VersionPrefix>
<VersionPrefix>2.3.1</VersionPrefix>
<Authors>Serilog Contributors</Authors>
<TargetFrameworks>net45;netstandard1.1;netstandard1.2;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net45;netstandard1.1;netstandard1.2;netstandard2.0;netstandard2.1</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>Serilog.Sinks.PeriodicBatching</AssemblyName>
<RootNamespace>Serilog</RootNamespace>
Expand All @@ -19,8 +19,6 @@
<RepositoryUrl>https://github.com/serilog/serilog-sinks-periodicbatching</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<!-- Don't reference the full NETStandard.Library -->
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
</PropertyGroup>

<ItemGroup>
Expand All @@ -32,32 +30,12 @@
<Reference Include="Microsoft.CSharp" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.1' ">
<PackageReference Include="System.Collections.Concurrent" Version="4.0.12" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.2' ">
<PackageReference Include="System.Collections.Concurrent" Version="4.0.12" />
<PackageReference Include="System.Threading.Timer" Version="4.0.1" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.Collections.Concurrent" Version="4.0.12" />
<PackageReference Include="System.Threading.Timer" Version="4.0.1" />
</ItemGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net45' ">
<DefineConstants>$(DefineConstants);THREADING_TIMER</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.2' ">
<DefineConstants>$(DefineConstants);THREADING_TIMER</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<DefineConstants>$(DefineConstants);THREADING_TIMER</DefineConstants>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net45' or '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1' ">
<DefineConstants>$(DefineConstants);THREADING_TIMER;EXECUTION_CONTEXT</DefineConstants>
</PropertyGroup>




</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Serilog.Sinks.PeriodicBatching
{
class BoundedConcurrentQueue<T>
{
public const int Unbounded = -1;
const int Unbounded = -1;

readonly ConcurrentQueue<T> _queue = new ConcurrentQueue<T>();
readonly int _queueLimit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ namespace Serilog.Sinks.PeriodicBatching
public class PeriodicBatchingSink : ILogEventSink, IDisposable, IBatchedLogEventSink
{
/// <summary>
/// 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.
/// </summary>
public const int NoQueueLimit = BoundedConcurrentQueue<LogEvent>.Unbounded;
[Obsolete("Implement `IBatchedLogEventSink` and use the `PeriodicBatchingSinkOptions` constructor.")]
public const int NoQueueLimit = -1;

readonly IBatchedLogEventSink _batchedLogEventSink;
readonly int _batchSizeLimit;
Expand Down Expand Up @@ -76,6 +77,7 @@ public PeriodicBatchingSink(IBatchedLogEventSink batchedSink, PeriodicBatchingSi
/// </summary>
/// <param name="batchSizeLimit">The maximum number of events to include in a single batch.</param>
/// <param name="period">The time to wait between checking for event batches.</param>
[Obsolete("Implement `IBatchedLogEventSink` and use the `PeriodicBatchingSinkOptions` constructor.")]
protected PeriodicBatchingSink(int batchSizeLimit, TimeSpan period)
: this(new PeriodicBatchingSinkOptions
{
Expand All @@ -97,13 +99,14 @@ protected PeriodicBatchingSink(int batchSizeLimit, TimeSpan period)
/// <param name="batchSizeLimit">The maximum number of events to include in a single batch.</param>
/// <param name="period">The time to wait between checking for event batches.</param>
/// <param name="queueLimit">Maximum number of events in the queue - use <see cref="NoQueueLimit"/> for an unbounded queue.</param>
[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;
Expand Down Expand Up @@ -199,6 +202,7 @@ protected virtual void EmitBatch(IEnumerable<LogEvent> events)
protected virtual async Task EmitBatchAsync(IEnumerable<LogEvent> events)
#pragma warning restore 1998
{
// ReSharper disable once MethodHasAsyncOverload
EmitBatch(events);
}

Expand Down Expand Up @@ -337,6 +341,7 @@ protected virtual void OnEmptyBatch()
protected virtual async Task OnEmptyBatchAsync()
#pragma warning restore 1998
{
// ReSharper disable once MethodHasAsyncOverload
OnEmptyBatch();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public class PeriodicBatchingSinkOptions

/// <summary>
/// Maximum number of events to hold in the sink's internal queue, or <c>null</c>
/// for an unbounded queue. The default is <c>10000</c>.
/// for an unbounded queue. The default is <c>100000</c>.
/// </summary>
public int? QueueLimit { get; set; } = 100000;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ public PortableTimer(Func<CancellationToken, Task> 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
}

Expand Down Expand Up @@ -88,7 +91,7 @@ async void OnTick()
{
return;
}
}
}

_running = true;
}
Expand All @@ -115,7 +118,7 @@ async void OnTick()
public void Dispose()
{
_cancel.Cancel();

lock (_stateLock)
{
if (_disposed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
}
}
}

0 comments on commit 3d73c17

Please sign in to comment.