[GFX-189] feature/GFX-189 - #96
Conversation
将 LogHandler.Create 的 Cognitive Complexity 由 34 降至 ≤5(Sonar S3776 修复)。 方法体只保留入口协调(参数校验 / Serilog 诊断调用 / 路径解析 / sink 装配调用 / 默认 logger 设置),其 余职责抽到 11 个 private static helper:ResolveLogPath / SelectOutputTemplates / ApplyLoki / BuildLokiLabels / ApplyLokiProperties / WriteLokiSink / BuildLokiCredentials / ApplyMongoDb / ApplyFile / ApplyConsole / ApplyMinimumLevel。public 签名与可观察行为零变更。 新增 GameFrameX.Foundation.Tests/Logger/LogHandlerCreateTests.cs 5 个 [Fact] 覆盖参数校验、 可用 logger 返回、configurationAction 回调、目录自动创建,使用独立 [Collection] 与 per-test 临时 目录隔离全局 Serilog / LogHelper 状态。dotnet build 0 错误,dotnet test 1802 通过 / 0 失败。 Linear: GFX-186
Linear: GFX-189
📝 WalkthroughWalkthroughChangesLogHandler.Create 将日志配置流程拆分为路径解析、模板选择及各类 sink 装配方法,并保留全局 logger 设置与异常处理行为。新增创建流程测试,同时调整资源释放测试的异常断言方式。 日志创建流程
Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@GameFrameX.Foundation.Logger/LogHandler.cs`:
- Line 215: Update the fallback filename expression near logFileName to treat an
empty or whitespace-only LogTagName as absent, falling back to LogType instead
of producing _.log; preserve the existing explicit LogFileName precedence and
append _.log to the selected type or tag.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: ca83f3cc-0335-4119-90f2-f20489991d39
📒 Files selected for processing (3)
GameFrameX.Foundation.Logger/LogHandler.csGameFrameX.Foundation.Tests/Localization/ResourceManagerTests.csGameFrameX.Foundation.Tests/Logger/LogHandlerCreateTests.cs
| private static string ResolveLogPath(LogOptions logOptions, bool isDefault) | ||
| { | ||
| // 文件名 | ||
| var logFileName = logOptions.LogFileName.IsNotNullOrEmptyOrWhiteSpace() ? logOptions.LogFileName : $"{logOptions.LogTagName ?? logOptions.LogType}_.log"; |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
空 LogTagName 时默认文件名错误。
LogTagName 默认是空字符串,?? 不会回退到 LogType,因此未指定 LogFileName 时会生成 _.log,而不是预期的 {LogType}_.log。
建议修复
- var logFileName = logOptions.LogFileName.IsNotNullOrEmptyOrWhiteSpace() ? logOptions.LogFileName : $"{logOptions.LogTagName ?? logOptions.LogType}_.log";
+ var fileNamePrefix = logOptions.LogTagName.IsNotNullOrEmptyOrWhiteSpace()
+ ? logOptions.LogTagName
+ : logOptions.LogType;
+ var logFileName = logOptions.LogFileName.IsNotNullOrEmptyOrWhiteSpace()
+ ? logOptions.LogFileName
+ : $"{fileNamePrefix}_.log";📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| var logFileName = logOptions.LogFileName.IsNotNullOrEmptyOrWhiteSpace() ? logOptions.LogFileName : $"{logOptions.LogTagName ?? logOptions.LogType}_.log"; | |
| var fileNamePrefix = logOptions.LogTagName.IsNotNullOrEmptyOrWhiteSpace() | |
| ? logOptions.LogTagName | |
| : logOptions.LogType; | |
| var logFileName = logOptions.LogFileName.IsNotNullOrEmptyOrWhiteSpace() | |
| ? logOptions.LogFileName | |
| : $"{fileNamePrefix}_.log"; |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@GameFrameX.Foundation.Logger/LogHandler.cs` at line 215, Update the fallback
filename expression near logFileName to treat an empty or whitespace-only
LogTagName as absent, falling back to LogType instead of producing _.log;
preserve the existing explicit LogFileName precedence and append _.log to the
selected type or tag.



Linear: GFX-189
Summary by CodeRabbit
重构
测试