feat: 初始功能
This commit is contained in:
39
Models/AppLogEntry.cs
Normal file
39
Models/AppLogEntry.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
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()
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user