namespace CloudPrint.Client.Models; public enum AppLogLevel { Info, Success, Warning, Error } public sealed class AppLogEntry { public DateTime Timestamp { get; init; } = DateTime.Now; public AppLogLevel Level { get; init; } = AppLogLevel.Info; public string Message { get; init; } = string.Empty; public string ExceptionText { get; init; } = string.Empty; public string LevelText => Level switch { AppLogLevel.Success => "成功", AppLogLevel.Warning => "警告", AppLogLevel.Error => "错误", _ => "信息" }; public string DisplayText => string.IsNullOrWhiteSpace(ExceptionText) ? $"[{Timestamp:HH:mm:ss}] [{LevelText}] {Message}" : $"[{Timestamp:HH:mm:ss}] [{LevelText}] {Message}(详见本地日志)"; public static AppLogEntry FromException(string message, Exception exception) { return new AppLogEntry { Level = AppLogLevel.Error, Message = message, ExceptionText = exception.ToString() }; } }