mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-05-06 16:16:44 +08:00
fix(core-tests): 收口 LoggerTests 日志集合抽象
- 修复 TestLogger.Logs 暴露 List<LogEntry> 实现类型导致的 MA0016 warning - 保持测试桩内部写入顺序和现有测试访问方式不变
This commit is contained in:
parent
a7fa70e4fe
commit
9f6204d6e2
@ -425,6 +425,8 @@ public class LoggerTests
|
||||
/// </summary>
|
||||
public sealed class TestLogger : AbstractLogger
|
||||
{
|
||||
private readonly List<LogEntry> _logs = new();
|
||||
|
||||
/// <summary>
|
||||
/// 初始化TestLogger的新实例
|
||||
/// </summary>
|
||||
@ -435,9 +437,9 @@ public sealed class TestLogger : AbstractLogger
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取记录的日志条目列表
|
||||
/// 获取按写入顺序保存的日志条目只读视图
|
||||
/// </summary>
|
||||
public List<LogEntry> Logs { get; } = new();
|
||||
public IReadOnlyList<LogEntry> Logs => _logs;
|
||||
|
||||
/// <summary>
|
||||
/// 将日志信息写入内部存储
|
||||
@ -447,7 +449,7 @@ public sealed class TestLogger : AbstractLogger
|
||||
/// <param name="exception">相关异常(可选)</param>
|
||||
protected override void Write(LogLevel level, string message, Exception? exception)
|
||||
{
|
||||
Logs.Add(new LogEntry(level, message, exception));
|
||||
_logs.Add(new LogEntry(level, message, exception));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -457,4 +459,4 @@ public sealed class TestLogger : AbstractLogger
|
||||
/// <param name="Message">日志消息</param>
|
||||
/// <param name="Exception">相关异常(可选)</param>
|
||||
public sealed record LogEntry(LogLevel Level, string Message, Exception? Exception);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user