GwWuYou ab5ea42350 feat(logging): 添加日志生成器功能
- 实现了 LoggerGenerator 源代码生成器,为标记 LogAttribute 的类自动生成日志字段
- 添加了 LogAttribute 特性,支持配置日志分类、字段名、访问修饰符和静态属性
- 创建了 Diagnostics 静态类,定义 GFLOG001 诊断规则检查 partial 类声明
- 集成 Microsoft.CodeAnalysis 包,启用增量生成器和扩展分析器规则
- 生成的代码包含命名空间、类名和日志字段的完整实现
2025-12-23 21:04:53 +08:00

32 lines
982 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; }
/// <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";
/// <summary>
/// 初始化 LogAttribute 类的新实例
/// </summary>
/// <param name="category">日志分类名,默认使用类名</param>
public LogAttribute(string? category = null)
{
Category = category;
}
}