using GFramework.Core.Abstractions.Logging;
using GFramework.Core.Logging;
namespace GFramework.Core.Tests.Logging;
///
/// 表示供日志相关测试复用的内存日志记录器。
///
public sealed class TestLogger : AbstractLogger
{
private readonly List _logs = new();
///
/// 初始化 的新实例。
///
/// 日志记录器的名称;未指定时沿用基类默认行为。
/// 允许写入的最小日志级别。
public TestLogger(string? name = null, LogLevel minLevel = LogLevel.Info) : base(name, minLevel)
{
}
///
/// 获取按写入顺序保存的日志条目只读视图。
///
public IReadOnlyList Logs => _logs;
///
/// 将日志信息追加到内存列表,供断言读取。
///
/// 日志级别。
/// 日志消息。
/// 相关异常;没有异常时为 。
protected override void Write(LogLevel level, string message, Exception? exception)
{
_logs.Add(new LogEntry(level, message, exception));
}
///
/// 表示单个日志条目的不可变快照。
///
/// 日志级别。
/// 日志消息。
/// 相关异常;没有异常时为 。
public sealed record LogEntry(LogLevel Level, string Message, Exception? Exception);
}