33 lines
1007 B
C#
33 lines
1007 B
C#
namespace WirelessTextSyncer.Windows.Services;
|
|
|
|
public static class AppLogger
|
|
{
|
|
private static readonly object SyncRoot = new();
|
|
private static readonly string LogDirectory = Path.Combine(
|
|
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
|
"WirelessTextSyncer");
|
|
|
|
public static string LogPath => Path.Combine(LogDirectory, "desktop.log");
|
|
|
|
public static void Info(string message)
|
|
{
|
|
Write("INFO", message);
|
|
}
|
|
|
|
public static void Error(string message, Exception? exception = null)
|
|
{
|
|
Write("ERROR", exception is null ? message : $"{message}{Environment.NewLine}{exception}");
|
|
}
|
|
|
|
private static void Write(string level, string message)
|
|
{
|
|
lock (SyncRoot)
|
|
{
|
|
Directory.CreateDirectory(LogDirectory);
|
|
File.AppendAllText(
|
|
LogPath,
|
|
$"{DateTimeOffset.Now:yyyy-MM-dd HH:mm:ss.fff zzz} [{level}] {message}{Environment.NewLine}");
|
|
}
|
|
}
|
|
}
|