mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 19:03:29 +08:00
- 将 AbstractLogger 实现从 ILogger 扩展为 IStructuredLogger 接口 - 添加通用日志方法 Log(LogLevel, string, params object[]) 支持格式化参数 - 实现结构化日志方法支持属性键值对记录 - 添加 ConsoleAppender、FileAppender 和 AsyncLogAppender 日志输出器 - 实现 CompositeFilter 过滤器和 DefaultLogFormatter、JsonLogFormatter 格式化器 - 在 ConsoleLogger 和 GodotLogger 中使用预缓存的日志级别字符串提升性能 - 使用 ANSI 颜色代码替代 ConsoleColor 实现跨平台日志着色 - 在 ConsoleLoggerFactoryProvider 和 GodotLoggerFactoryProvider 中添加日志工厂缓存 - 优化 FileStorage 中目录遍历使用 OfType<string>() 类型转换 - 添加 LogContext 支持异步流中的结构化属性传递
37 lines
1.0 KiB
C#
37 lines
1.0 KiB
C#
namespace GFramework.Core.Abstractions.logging;
|
|
|
|
/// <summary>
|
|
/// 日志条目,包含完整的日志信息
|
|
/// </summary>
|
|
public sealed record LogEntry(
|
|
DateTime Timestamp,
|
|
LogLevel Level,
|
|
string LoggerName,
|
|
string Message,
|
|
Exception? Exception,
|
|
IReadOnlyDictionary<string, object?>? Properties)
|
|
{
|
|
/// <summary>
|
|
/// 获取合并了上下文属性的所有属性
|
|
/// </summary>
|
|
/// <returns>包含日志属性和上下文属性的字典</returns>
|
|
public IReadOnlyDictionary<string, object?> GetAllProperties()
|
|
{
|
|
var contextProps = LogContext.Current;
|
|
|
|
if (Properties == null || Properties.Count == 0)
|
|
return contextProps;
|
|
|
|
if (contextProps.Count == 0)
|
|
return Properties;
|
|
|
|
// 合并属性,日志属性优先
|
|
var merged = new Dictionary<string, object?>(contextProps, StringComparer.Ordinal);
|
|
foreach (var prop in Properties)
|
|
{
|
|
merged[prop.Key] = prop.Value;
|
|
}
|
|
|
|
return merged;
|
|
}
|
|
} |