forked from akkadotnet/Akka.Logger.Serilog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestSink.cs
More file actions
46 lines (38 loc) · 1.24 KB
/
Copy pathTestSink.cs
File metadata and controls
46 lines (38 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System.Collections.Concurrent;
using Serilog.Core;
using Serilog.Events;
using Xunit;
using Xunit.Abstractions;
[assembly: CollectionBehavior(DisableTestParallelization = true)]
namespace Akka.Logger.Serilog.Tests
{
/// <inheritdoc />
/// <summary>
/// Basic concurrent sink implementation for testing the final output from Serilog
/// </summary>
public sealed class TestSink : ILogEventSink
{
public ConcurrentQueue<global::Serilog.Events.LogEvent> Writes { get; private set; } = new ConcurrentQueue<global::Serilog.Events.LogEvent>();
private readonly ITestOutputHelper _output;
private int _count;
public TestSink(): this(null)
{ }
public TestSink(ITestOutputHelper output)
{
_output = output;
}
/// <summary>
/// Resets the contents of the queue
/// </summary>
public void Clear()
{
Writes = new ConcurrentQueue<LogEvent>();
}
public void Emit(global::Serilog.Events.LogEvent logEvent)
{
_count++;
_output?.WriteLine($"[{nameof(TestSink)}][{_count}]: {logEvent.RenderMessage()}");
Writes.Enqueue(logEvent);
}
}
}