-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from serilog/dev
2.3.0 Release
- Loading branch information
Showing
15 changed files
with
346 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -236,3 +236,6 @@ _Pvt_Extensions | |
.fake/ | ||
|
||
BenchmarkDotNet.Artifacts/ | ||
.idea | ||
*.orig | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,53 @@ | ||
# Serilog.Sinks.PeriodicBatching | ||
# Serilog.Sinks.PeriodicBatching [![Build status](https://ci.appveyor.com/api/projects/status/w2agqyd8rn0jur9y?svg=true)](https://ci.appveyor.com/project/serilog/serilog-sinks-periodicbatching) [![NuGet Version](http://img.shields.io/nuget/v/Serilog.Sinks.periodicbatching.svg?style=flat)](https://www.nuget.org/packages/Serilog.Sinks.periodicbatching/) | ||
|
||
A base for Serilog sinks that batch and asynchronously send events to a slow/remote target. | ||
A wrapper for Serilog sinks that asynchronously emits events in batches, useful when logging to a slow and/or remote target. | ||
|
||
[![Build status](https://ci.appveyor.com/api/projects/status/w2agqyd8rn0jur9y?svg=true)](https://ci.appveyor.com/project/serilog/serilog-sinks-periodicbatching) [![NuGet Version](http://img.shields.io/nuget/v/Serilog.Sinks.periodicbatching.svg?style=flat)](https://www.nuget.org/packages/Serilog.Sinks.periodicbatching/) | ||
### Getting started | ||
|
||
* [Documentation](https://github.com/serilog/serilog/wiki) | ||
Sinks that, for performance reasons, need to emit events in batches, can be implemented using `PeriodicBatchingSink` | ||
from this package. | ||
|
||
Copyright © 2016 Serilog Contributors - Provided under the [Apache License, Version 2.0](http://apache.org/licenses/LICENSE-2.0.html). | ||
First, install the package into your Sink project: | ||
|
||
``` | ||
dotnet add package Serilog.Sinks.PeriodicBatching | ||
``` | ||
|
||
Then, instead of implementing Serilog's `ILogEventSink`, implement `IBatchedLogEventSink` in your sink class: | ||
|
||
```csharp | ||
class ExampleBatchedSink : IBatchedLogEventSink | ||
{ | ||
public async Task EmitBatchAsync(IEnumerable<LogEvent> batch) | ||
{ | ||
foreach (var logEvent in batch) | ||
Console.WriteLine(logEvent); | ||
} | ||
|
||
public Task OnEmptyBatchAsync() { } | ||
} | ||
``` | ||
|
||
Finally, in your sink's configuration method, construct a `PeriodicBatchingSink` that wraps your batched sink: | ||
|
||
```csharp | ||
public static class LoggerSinkExampleConfiguration | ||
{ | ||
public static LoggerConfiguration Example(this LoggerSinkConfiguration loggerSinkConfiguration) | ||
{ | ||
var exampleSink = new ExampleBatchedSink(); | ||
|
||
var batchingOptions = new PeriodicBatchingSinkOptions | ||
{ | ||
BatchSize = 100, | ||
Period = TimeSpan.FromSeconds(2), | ||
EagerlyEmitFirstEvent = true, | ||
QueueSizeLimit = 10000 | ||
}; | ||
|
||
var batchingSink = new PeriodicBatchingSink(exampleSink, batchingOptions); | ||
|
||
return loggerSinkConfiguration.Sink(batchingSink); | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=backoff/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=liveness/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=ramping/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Serilog/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/UserDictionary/Words/=sink_0027s/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> |
5 changes: 3 additions & 2 deletions
5
src/Serilog.Sinks.PeriodicBatching/Serilog.Sinks.PeriodicBatching.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/Serilog.Sinks.PeriodicBatching/Sinks/PeriodicBatching/IBatchedLogEventSink.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2013-2020 Serilog Contributors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Serilog.Events; | ||
|
||
namespace Serilog.Sinks.PeriodicBatching | ||
{ | ||
/// <summary> | ||
/// Interface for targets that accept events in batches. | ||
/// </summary> | ||
public interface IBatchedLogEventSink | ||
{ | ||
/// <summary> | ||
/// Emit a batch of log events, running asynchronously. | ||
/// </summary> | ||
/// <param name="batch">The batch of events to emit.</param> | ||
Task EmitBatchAsync(IEnumerable<LogEvent> batch); | ||
|
||
/// <summary> | ||
/// Allows sinks to perform periodic work without requiring additional threads | ||
/// or timers (thus avoiding additional flush/shut-down complexity). | ||
/// </summary> | ||
Task OnEmptyBatchAsync(); | ||
} | ||
} |
Oops, something went wrong.