-
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 #98 from nblumhardt/failure-listeners
Support `ILoggingFailureListener` and fallback sinks
- Loading branch information
Showing
7 changed files
with
97 additions
and
8 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
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
46 changes: 46 additions & 0 deletions
46
test/Serilog.Sinks.Async.Tests/Support/CollectingFailureListener.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,46 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Serilog.Core; | ||
using Serilog.Events; | ||
|
||
namespace Serilog.Sinks.Async.Tests.Support; | ||
|
||
class CollectingFailureListener: ILoggingFailureListener | ||
{ | ||
readonly object _sync = new(); | ||
readonly List<LogEvent> _events = []; | ||
readonly List<Exception> _exceptions = []; | ||
|
||
public IReadOnlyList<LogEvent> Events | ||
{ | ||
get | ||
{ | ||
lock (_sync) | ||
return _events.ToList(); | ||
} | ||
} | ||
public IReadOnlyList<Exception> Exceptions | ||
{ | ||
get | ||
{ | ||
lock (_sync) | ||
return _exceptions.ToList(); | ||
} | ||
} | ||
|
||
public void OnLoggingFailed(object sender, LoggingFailureKind kind, string message, IReadOnlyCollection<LogEvent> events, | ||
Exception exception) | ||
{ | ||
lock (_sync) | ||
{ | ||
if (exception != null) | ||
_exceptions.Add(exception); | ||
|
||
foreach (var logEvent in events ?? []) | ||
{ | ||
_events.Add(logEvent); | ||
} | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
test/Serilog.Sinks.Async.Tests/Support/NotImplementedSink.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,13 @@ | ||
using System; | ||
using Serilog.Core; | ||
using Serilog.Events; | ||
|
||
namespace Serilog.Sinks.Async.Tests.Support; | ||
|
||
class NotImplementedSink: ILogEventSink | ||
{ | ||
public void Emit(LogEvent logEvent) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} |