gewuyou ba4ace8d40 test(analyzer): 收敛 Core.Tests 与 Cqrs.Tests 警告批次
- 拆分 GameContextTests、ArchitectureServicesTests、RegistryInitializationHookBaseTests 与 Cqrs 测试辅助类型,消除批次内 MA0048 热点
- 修复 Core.Tests 零散可空性、集合抽象和测试辅助 warning,使受影响 Release 构建清零
- 更新 analyzer-warning-reduction 跟踪与 trace,记录 236 条仓库根 warning 基线和 45/50 停止点
2026-04-28 08:32:00 +08:00

46 lines
1.7 KiB
C#

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