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

38
Services/FileAppLogger.cs Normal file
View File

@@ -0,0 +1,38 @@
using System.IO;
using CloudPrint.Client.Models;
using CloudPrint.Client.Services.Abstractions;
namespace CloudPrint.Client.Services;
public sealed class FileAppLogger : IAppLogger
{
private readonly object _syncRoot = new();
public FileAppLogger()
{
var appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
LogDirectory = Path.Combine(appData, "CloudPrint.Client", "logs");
}
public string LogDirectory { get; }
public void Write(AppLogEntry entry)
{
ArgumentNullException.ThrowIfNull(entry);
Directory.CreateDirectory(LogDirectory);
var logPath = Path.Combine(LogDirectory, $"cloudprint-{DateTime.Now:yyyyMMdd}.log");
lock (_syncRoot)
{
File.AppendAllText(logPath, Format(entry) + Environment.NewLine);
}
}
private static string Format(AppLogEntry entry)
{
var exceptionText = string.IsNullOrWhiteSpace(entry.ExceptionText)
? string.Empty
: $" | Exception={entry.ExceptionText}";
return $"{entry.Timestamp:yyyy-MM-dd HH:mm:ss.fff} [{entry.LevelText}] {entry.Message}{exceptionText}";
}
}