feat: 初始功能

This commit is contained in:
Shiqvlizi Name
2026-05-23 18:16:50 +08:00
parent a5bfd8792e
commit 9a51259e9e
63 changed files with 5377 additions and 1 deletions

39
Models/AppLogEntry.cs Normal file
View 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()
};
}
}