Skip to content

Commit d9a9039

Browse files
authored
Merge pull request #42 from datalust/dev
6.0.0 Release
2 parents 5da9318 + 9701e93 commit d9a9039

13 files changed

Lines changed: 402 additions & 186 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class Startup
2525
{
2626
public void ConfigureServices(IServiceCollection services)
2727
{
28-
// Added
28+
// Added; requires `using Microsoft.Extensions.Logging;`
2929
services.AddLogging(builder => builder.AddSeq())
3030

3131
// Other configuration follows...

src/Seq.Extensions.Logging/Microsoft/Extensions/Logging/SeqLoggerExtensions.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Serilog.Sinks.Seq;
99
using Microsoft.Extensions.DependencyInjection;
1010
using Microsoft.Extensions.Logging.Configuration;
11+
using Serilog.Sinks.PeriodicBatching;
1112

1213
namespace Microsoft.Extensions.Logging
1314
{
@@ -180,10 +181,8 @@ static SerilogLoggerProvider CreateProvider(
180181
var sink = new SeqSink(
181182
serverUrl,
182183
apiKey,
183-
1000,
184-
TimeSpan.FromSeconds(2),
185184
256 * 1024,
186-
levelSwitch,
185+
new ControlledLevelSwitch(levelSwitch),
187186
null);
188187

189188
LevelOverrideMap overrideMap = null;
@@ -198,7 +197,13 @@ static SerilogLoggerProvider CreateProvider(
198197
overrideMap = new LevelOverrideMap(overrides, levelSwitch);
199198
}
200199

201-
var logger = new Logger(levelSwitch, sink, sink.Dispose, overrideMap);
200+
var batchingSink = new PeriodicBatchingSink(sink, new PeriodicBatchingSinkOptions
201+
{
202+
BatchSizeLimit = 1000,
203+
Period = TimeSpan.FromSeconds(2),
204+
});
205+
206+
var logger = new Logger(levelSwitch, batchingSink, batchingSink.Dispose, overrideMap);
202207
var provider = new SerilogLoggerProvider(logger);
203208
return provider;
204209
}

src/Seq.Extensions.Logging/Seq.Extensions.Logging.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<Description>Add centralized structured log collection to ASP.NET Core apps with one line of code.</Description>
5-
<VersionPrefix>5.0.0</VersionPrefix>
5+
<VersionPrefix>6.0.0</VersionPrefix>
66
<Authors>Datalust and Contributors</Authors>
77
<TargetFrameworks>net462;netstandard2.0;net5.0</TargetFrameworks>
88
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
@@ -14,7 +14,7 @@
1414
<PackageIcon>icon.png</PackageIcon>
1515
<PackageProjectUrl>https://github.com/datalust/seq-extensions-logging</PackageProjectUrl>
1616
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
17-
<RootNamespace/>
17+
<RootNamespace />
1818
</PropertyGroup>
1919

2020
<ItemGroup>
@@ -26,5 +26,4 @@
2626
<ItemGroup>
2727
<None Include="..\..\asset\icon.png" Pack="true" Visible="false" PackagePath="" />
2828
</ItemGroup>
29-
3029
</Project>

src/Seq.Extensions.Logging/Serilog/Sinks/PeriodicBatching/BatchedConnectionStatus.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2013-2016 Serilog Contributors
1+
// Copyright 2013-2020 Serilog Contributors
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@ namespace Serilog.Sinks.PeriodicBatching
1919
/// <summary>
2020
/// Manages reconnection period and transient fault response for <see cref="PeriodicBatchingSink"/>.
2121
/// During normal operation an object of this type will simply echo the configured batch transmission
22-
/// period. When availabilty fluctuates, the class tracks the number of failed attempts, each time
22+
/// period. When availability fluctuates, the class tracks the number of failed attempts, each time
2323
/// increasing the interval before reconnection is attempted (up to a set maximum) and at predefined
2424
/// points indicating that either the current batch, or entire waiting queue, should be dropped. This
2525
/// Serves two purposes - first, a loaded receiver may need a temporary reduction in traffic while coming

src/Seq.Extensions.Logging/Serilog/Sinks/PeriodicBatching/BoundedConcurrentQueue.cs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 Serilog Contributors
1+
// Copyright 2013-2020 Serilog Contributors
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -18,33 +18,28 @@
1818

1919
namespace Serilog.Sinks.PeriodicBatching
2020
{
21-
class BoundedConcurrentQueue<T>
21+
class BoundedConcurrentQueue<T>
2222
{
23-
const int NON_BOUNDED = -1;
23+
const int Unbounded = -1;
2424

2525
readonly ConcurrentQueue<T> _queue = new ConcurrentQueue<T>();
2626
readonly int _queueLimit;
2727

2828
int _counter;
2929

30-
public BoundedConcurrentQueue()
30+
public BoundedConcurrentQueue(int? queueLimit = null)
3131
{
32-
_queueLimit = NON_BOUNDED;
33-
}
34-
35-
public BoundedConcurrentQueue(int queueLimit)
36-
{
37-
if (queueLimit <= 0)
38-
throw new ArgumentOutOfRangeException(nameof(queueLimit), "queue limit must be positive");
32+
if (queueLimit.HasValue && queueLimit <= 0)
33+
throw new ArgumentOutOfRangeException(nameof(queueLimit), "Queue limit must be positive, or `null` to indicate unbounded.");
3934

40-
_queueLimit = queueLimit;
35+
_queueLimit = queueLimit ?? Unbounded;
4136
}
4237

4338
public int Count => _queue.Count;
4439

4540
public bool TryDequeue(out T item)
4641
{
47-
if (_queueLimit == NON_BOUNDED)
42+
if (_queueLimit == Unbounded)
4843
return _queue.TryDequeue(out item);
4944

5045
var result = false;
@@ -64,7 +59,7 @@ public bool TryDequeue(out T item)
6459

6560
public bool TryEnqueue(T item)
6661
{
67-
if (_queueLimit == NON_BOUNDED)
62+
if (_queueLimit == Unbounded)
6863
{
6964
_queue.Enqueue(item);
7065
return true;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2013-2020 Serilog Contributors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using System.Collections.Generic;
16+
using System.Threading.Tasks;
17+
using Serilog.Events;
18+
19+
namespace Serilog.Sinks.PeriodicBatching
20+
{
21+
/// <summary>
22+
/// Interface for targets that accept events in batches.
23+
/// </summary>
24+
interface IBatchedLogEventSink
25+
{
26+
/// <summary>
27+
/// Emit a batch of log events, running asynchronously.
28+
/// </summary>
29+
/// <param name="batch">The batch of events to emit.</param>
30+
Task EmitBatchAsync(IEnumerable<LogEvent> batch);
31+
32+
/// <summary>
33+
/// Allows sinks to perform periodic work without requiring additional threads
34+
/// or timers (thus avoiding additional flush/shut-down complexity).
35+
/// </summary>
36+
Task OnEmptyBatchAsync();
37+
}
38+
}

0 commit comments

Comments
 (0)