Initial commit: WpywMail 自建邮件系统:.NET 8 原生 SMTP/IMAP 服务端(DKIM 签名、SPF/DKIM/DMARC 入站校验、SQLite 存储、完整账号体系)、Node 服务端、WinUI 3 客户端与 Web 前端
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
using System.Text;
|
||||
|
||||
namespace WpywMail.Native;
|
||||
|
||||
public static class AppLog
|
||||
{
|
||||
private static readonly object Gate = new();
|
||||
private static string path = "";
|
||||
|
||||
public static void Configure(AppConfig config)
|
||||
{
|
||||
Directory.CreateDirectory(config.DataDirectory);
|
||||
path = Path.Combine(config.DataDirectory, "service.log");
|
||||
Info("日志系统已启动。");
|
||||
}
|
||||
|
||||
public static void Info(string message) => Write("信息", message);
|
||||
public static void Warn(string message) => Write("警告", message);
|
||||
public static void Error(string message) => Write("错误", message);
|
||||
|
||||
private static void Write(string level, string message)
|
||||
{
|
||||
var line = $"{DateTimeOffset.Now:yyyy-MM-dd HH:mm:ss zzz} [{level}] {message}";
|
||||
Console.WriteLine(line);
|
||||
if (string.IsNullOrWhiteSpace(path)) return;
|
||||
try
|
||||
{
|
||||
lock (Gate) File.AppendAllText(path, line + Environment.NewLine, new UTF8Encoding(false));
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user