From 8496bf43bbcc63e1e1412bcb4b00ceb237b3ddf2 Mon Sep 17 00:00:00 2001 From: GwWuYou <95328647+GeWuYou@users.noreply.github.com> Date: Sun, 28 Dec 2025 11:45:24 +0800 Subject: [PATCH] =?UTF-8?q?refactor(logging):=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E7=B3=BB=E7=BB=9F=E6=8A=BD=E8=B1=A1=E5=92=8C?= =?UTF-8?q?=E7=9B=AE=E6=A0=87=E6=A1=86=E6=9E=B6=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 RootLoggerName 常量从接口移至具体实现类 AbstractLogger - 在 AbstractLogger 中添加 IsEnabledForLevel 方法的完整实现 - 更新 ILogger 接口移除 IsEnabledForLevel 的默认实现 - 统一所有项目的目标框架为 netstandard2.0 - 修正命名空间引用确保日志相关类型正确导入 - 添加详细的 XML 文档注释提升代码可读性 - 优化项目构建属性配置支持更高版本的语言特性 --- .../Directory.Build.props | 10 ++++-- .../logging/ILogger.cs | 24 ++------------ .../logging/LogLevel.cs | 2 +- GFramework.Core/logging/AbstractLogger.cs | 32 ++++++++++++++++--- .../Directory.Build.props | 10 ++++-- .../GFramework.Godot.SourceGenerators.csproj | 2 +- .../Directory.Build.props | 10 ++++-- .../Directory.Build.props | 10 ++++-- .../GFramework.SourceGenerators.csproj | 2 +- 9 files changed, 61 insertions(+), 41 deletions(-) diff --git a/GFramework.Core.Abstractions/Directory.Build.props b/GFramework.Core.Abstractions/Directory.Build.props index 638b238..1e6c3bf 100644 --- a/GFramework.Core.Abstractions/Directory.Build.props +++ b/GFramework.Core.Abstractions/Directory.Build.props @@ -1,12 +1,16 @@  - + - net8.0;net9.0;net10.0 + netstandard2.0 true true + preview - all diff --git a/GFramework.Core.Abstractions/logging/ILogger.cs b/GFramework.Core.Abstractions/logging/ILogger.cs index ee0944d..185d604 100644 --- a/GFramework.Core.Abstractions/logging/ILogger.cs +++ b/GFramework.Core.Abstractions/logging/ILogger.cs @@ -1,18 +1,10 @@ -using System; -using GFramework.Core.logging; - -namespace GFramework.Core.Abstractions.logging; +namespace GFramework.Core.Abstractions.logging; /// /// 定义日志记录接口,提供日志记录和级别检查功能 /// public interface ILogger { - /// - /// 根日志记录器的名称常量 - /// - public const string RootLoggerName = "ROOT"; - /// /// 获取日志记录器的名称 /// @@ -62,19 +54,7 @@ public interface ILogger /// /// 要检查的日志级别 /// 如果指定的日志级别已启用则返回true,否则返回false - bool IsEnabledForLevel(LogLevel level) - { - return level switch - { - LogLevel.Trace => IsTraceEnabled(), - LogLevel.Debug => IsDebugEnabled(), - LogLevel.Info => IsInfoEnabled(), - LogLevel.Warning => IsWarnEnabled(), - LogLevel.Error => IsErrorEnabled(), - LogLevel.Fatal => IsFatalEnabled(), - _ => throw new ArgumentException($"Level [{level}] not recognized.", nameof(level)) - }; - } + bool IsEnabledForLevel(LogLevel level); #endregion diff --git a/GFramework.Core.Abstractions/logging/LogLevel.cs b/GFramework.Core.Abstractions/logging/LogLevel.cs index 1bced4e..9f70f89 100644 --- a/GFramework.Core.Abstractions/logging/LogLevel.cs +++ b/GFramework.Core.Abstractions/logging/LogLevel.cs @@ -1,4 +1,4 @@ -namespace GFramework.Core.logging; +namespace GFramework.Core.Abstractions.logging; /// /// 定义日志级别的枚举,用于标识不同严重程度的日志消息 diff --git a/GFramework.Core/logging/AbstractLogger.cs b/GFramework.Core/logging/AbstractLogger.cs index 68d9470..35e9153 100644 --- a/GFramework.Core/logging/AbstractLogger.cs +++ b/GFramework.Core/logging/AbstractLogger.cs @@ -1,6 +1,4 @@ -using GFramework.Core.Abstractions.logging; - -namespace GFramework.Core.logging; +namespace GFramework.Core.logging; /// /// 日志抽象基类,封装日志级别判断、格式化与异常处理逻辑。 @@ -10,7 +8,12 @@ public abstract class AbstractLogger( string? name = null, LogLevel minLevel = LogLevel.Info) : ILogger { - private readonly string _name = name ?? ILogger.RootLoggerName; + /// + /// 根日志记录器的名称常量 + /// + public const string RootLoggerName = "ROOT"; + + private readonly string _name = name ?? RootLoggerName; #region Metadata @@ -99,6 +102,27 @@ public abstract class AbstractLogger( return IsEnabled(LogLevel.Fatal); } + /// + /// 检查指定日志级别是否启用 + /// + /// 要检查的日志级别 + /// 如果指定级别启用返回true,否则返回false + /// 当传入的日志级别不被识别时抛出 + public bool IsEnabledForLevel(LogLevel level) + { + // 根据不同的日志级别调用对应的检查方法 + return level switch + { + LogLevel.Trace => IsTraceEnabled(), + LogLevel.Debug => IsDebugEnabled(), + LogLevel.Info => IsInfoEnabled(), + LogLevel.Warning => IsWarnEnabled(), + LogLevel.Error => IsErrorEnabled(), + LogLevel.Fatal => IsFatalEnabled(), + _ => throw new ArgumentException($"Level [{level}] not recognized.", nameof(level)) + }; + } + #endregion #region Trace diff --git a/GFramework.Godot.SourceGenerators.Abstractions/Directory.Build.props b/GFramework.Godot.SourceGenerators.Abstractions/Directory.Build.props index daa5255..82f43af 100644 --- a/GFramework.Godot.SourceGenerators.Abstractions/Directory.Build.props +++ b/GFramework.Godot.SourceGenerators.Abstractions/Directory.Build.props @@ -1,12 +1,16 @@ - + - net8.0;net9.0;net10.0 + netstandard2.0 true true + preview - all diff --git a/GFramework.Godot.SourceGenerators/GFramework.Godot.SourceGenerators.csproj b/GFramework.Godot.SourceGenerators/GFramework.Godot.SourceGenerators.csproj index c59cbc1..d0c2e31 100644 --- a/GFramework.Godot.SourceGenerators/GFramework.Godot.SourceGenerators.csproj +++ b/GFramework.Godot.SourceGenerators/GFramework.Godot.SourceGenerators.csproj @@ -2,7 +2,7 @@ GeWuYou.GFramework.Godot.SourceGenerators - net8.0;net9.0;net10.0 + netstandard2.0 true diff --git a/GFramework.SourceGenerators.Abstractions/Directory.Build.props b/GFramework.SourceGenerators.Abstractions/Directory.Build.props index daa5255..82f43af 100644 --- a/GFramework.SourceGenerators.Abstractions/Directory.Build.props +++ b/GFramework.SourceGenerators.Abstractions/Directory.Build.props @@ -1,12 +1,16 @@ - + - net8.0;net9.0;net10.0 + netstandard2.0 true true + preview - all diff --git a/GFramework.SourceGenerators.Common/Directory.Build.props b/GFramework.SourceGenerators.Common/Directory.Build.props index daa5255..82f43af 100644 --- a/GFramework.SourceGenerators.Common/Directory.Build.props +++ b/GFramework.SourceGenerators.Common/Directory.Build.props @@ -1,12 +1,16 @@ - + - net8.0;net9.0;net10.0 + netstandard2.0 true true + preview - all diff --git a/GFramework.SourceGenerators/GFramework.SourceGenerators.csproj b/GFramework.SourceGenerators/GFramework.SourceGenerators.csproj index 888a09e..e43c807 100644 --- a/GFramework.SourceGenerators/GFramework.SourceGenerators.csproj +++ b/GFramework.SourceGenerators/GFramework.SourceGenerators.csproj @@ -2,7 +2,7 @@ GeWuYou.GFramework.SourceGenerators - net8.0;net9.0;net10.0 + netstandard2.0 true