GeWuYou fb61ae3198 refactor(logging): 优化日志生成器属性处理逻辑
- 将 LogAttribute 的 Category 属性改为可设置
- 添加了无参构造函数支持
- 移除了部分无效的诊断检查代码
- 为 LoggerGenerator 添加了可空引用类型支持
- 使用 switch 表达式简化参数解析逻辑
- 优化了命名参数获取方法的实现
2025-12-24 13:10:44 +08:00

32 lines
1009 B
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#nullable enable
using System;
namespace GFramework.Generator.Attributes.generator.logging;
/// <summary>
/// 标注在类上Source Generator 会为该类自动生成一个日志记录器字段。
/// </summary>
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
public sealed class LogAttribute : Attribute
{
/// <summary>日志分类名(默认使用类名)</summary>
public string? Category { get; set; }
/// <summary>生成字段名</summary>
public string FieldName { get; set; } = "_log";
/// <summary>是否生成 static 字段</summary>
public bool IsStatic { get; set; } = true;
/// <summary>访问修饰符</summary>
public string AccessModifier { get; set; } = "private";
public LogAttribute() { }
/// <summary>
/// 初始化 LogAttribute 类的新实例
/// </summary>
/// <param name="category">日志分类名,默认使用类名</param>
public LogAttribute(string? category)
{
Category = category;
}
}