GwWuYou d4b37345db feat(logging): 添加LogAttribute诊断验证功能
- 定义新的诊断描述符GFW_LOG001用于检测LogAttribute无法生成Logger的情况
- 在代码生成过程中验证LogAttribute是否存在及构造参数有效性
- 当LogAttribute缺失或参数无效时报告诊断错误并提供详细信息
- 修复代码格式化问题并优化代码生成逻辑
- 更新AnalyzerReleases.Unshipped.md文档添加新诊断规则
- 改进Generate方法参数传递和错误处理机制
2025-12-23 22:31:42 +08:00

40 lines
1.3 KiB
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.

using Microsoft.CodeAnalysis;
namespace GFramework.Generator.generator.logging;
/// <summary>
/// 提供诊断描述符的静态类用于GFramework日志生成器的编译时检查
/// </summary>
internal static class Diagnostics
{
/// <summary>
/// 定义诊断描述符:要求使用[Log]特性的类必须声明为partial
/// </summary>
/// <remarks>
/// 当类使用[Log]特性但未声明为partial时编译器将报告此错误
/// </remarks>
public static readonly DiagnosticDescriptor MustBePartial =
new(
id: "GFLOG001",
title: "Class must be partial",
messageFormat: "Class '{0}' must be declared partial to use [Log]",
category: "GFramework.Logging",
DiagnosticSeverity.Error,
isEnabledByDefault: true
);
/// <summary>
/// 定义诊断描述符LogAttribute无法生成Logger的错误情况
/// </summary>
public static readonly DiagnosticDescriptor LogAttributeInvalid =
new(
id: "GFW_LOG001",
title: "LogAttribute 无法生成 Logger",
messageFormat: "类 '{0}' 上的 LogAttribute 无法生效:{1}",
category: "GFramework.Logging",
DiagnosticSeverity.Warning,
isEnabledByDefault: true);
}