Files
client/Models/AppLogEntry.cs

39 lines
1.1 KiB
C#
Raw Permalink Normal View History

2026-05-23 18:16:50 +08:00
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()
};
}
}