초기커밋
This commit is contained in:
37
BrokerApiTest/Helper/TestLogger.cs
Normal file
37
BrokerApiTest/Helper/TestLogger.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
namespace BrokerTest.Helper;
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Xunit.Abstractions;
|
||||
|
||||
public class TestLogger<T> : ILogger<T>, IDisposable
|
||||
{
|
||||
private readonly List<string> m_logs = [];
|
||||
private readonly ITestOutputHelper m_output;
|
||||
|
||||
public TestLogger(ITestOutputHelper output)
|
||||
{
|
||||
m_output = output;
|
||||
}
|
||||
|
||||
public IDisposable? BeginScope<TState>(TState state) where TState : notnull
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool IsEnabled(LogLevel logLevel) => true;
|
||||
|
||||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception,
|
||||
Func<TState, Exception?, string> formatter)
|
||||
{
|
||||
var message = formatter(state, exception);
|
||||
m_logs.Add(message);
|
||||
m_output.WriteLine(message);
|
||||
}
|
||||
|
||||
public IEnumerable<string> Logs => m_logs;
|
||||
|
||||
public void Dispose() => m_logs.Clear();
|
||||
}
|
||||
Reference in New Issue
Block a user