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.
recyclarr/tests/Recyclarr.TestLibrary/TestableLogger.cs

29 lines
680 B

using JetBrains.Annotations;
using Serilog.Core;
using Serilog.Events;
namespace Recyclarr.TestLibrary;
[UsedImplicitly]
public sealed class TestableLogger : ILogger
{
private readonly Logger _log;
private readonly List<string> _messages = new();
public TestableLogger()
{
_log = new LoggerConfiguration()
.MinimumLevel.Is(LogEventLevel.Verbose)
.WriteTo.Observers(o => o.Subscribe(x => _messages.Add(x.RenderMessage())))
.WriteTo.Console()
.CreateLogger();
}
public void Write(LogEvent logEvent)
{
_log.Write(logEvent);
}
public IEnumerable<string> Messages => _messages;
}