namespace YZWater.Core.Models; /// /// 日志条目模型 /// public class LogEntry { /// 时间戳 public DateTime Timestamp { get; set; } = DateTime.Now; /// 日志级别(Information, Warning, Error, Debug) public string Level { get; set; } = "Information"; /// 日志消息 public string Message { get; set; } = string.Empty; /// 异常信息(可选) public string? Exception { get; set; } /// 来源(可选) public string? Source { get; set; } /// /// 从 Serilog 的 LogEvent 创建 LogEntry /// public static LogEntry FromSerilog(Serilog.Events.LogEvent logEvent) { return new LogEntry { Timestamp = logEvent.Timestamp.LocalDateTime, Level = logEvent.Level.ToString(), Message = logEvent.RenderMessage(), Exception = logEvent.Exception?.ToString(), Source = logEvent.Properties.TryGetValue("SourceContext", out var sourceContext) ? sourceContext.ToString().Trim('"') : null }; } }