You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
680 B
29 lines
680 B
1 year ago
|
using JetBrains.Annotations;
|
||
2 years ago
|
using Serilog.Core;
|
||
|
using Serilog.Events;
|
||
|
|
||
|
namespace Recyclarr.TestLibrary;
|
||
|
|
||
1 year ago
|
[UsedImplicitly]
|
||
|
public sealed class TestableLogger : ILogger
|
||
2 years ago
|
{
|
||
|
private readonly Logger _log;
|
||
1 year ago
|
private readonly List<string> _messages = new();
|
||
2 years ago
|
|
||
|
public TestableLogger()
|
||
|
{
|
||
|
_log = new LoggerConfiguration()
|
||
|
.MinimumLevel.Is(LogEventLevel.Verbose)
|
||
1 year ago
|
.WriteTo.Observers(o => o.Subscribe(x => _messages.Add(x.RenderMessage())))
|
||
2 years ago
|
.WriteTo.Console()
|
||
|
.CreateLogger();
|
||
|
}
|
||
|
|
||
|
public void Write(LogEvent logEvent)
|
||
|
{
|
||
|
_log.Write(logEvent);
|
||
|
}
|
||
|
|
||
1 year ago
|
public IEnumerable<string> Messages => _messages;
|
||
2 years ago
|
}
|