using System; using System.IO; using System.Text; namespace Terius.Automate.Agent.Services; public static class LocalLog { private static readonly object Sync = new(); public static string DirectoryPath { get; } = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "TERIUS", "Automate", "logs"); public static string CurrentFilePath => Path.Combine(DirectoryPath, $"agent-{DateTime.Now:yyyy-MM-dd}.log"); public static void Write(string message) { try { lock (Sync) { Directory.CreateDirectory(DirectoryPath); var line = $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}] {message}{Environment.NewLine}"; File.AppendAllText(CurrentFilePath, line, new UTF8Encoding(false)); } } catch { // Un fallo del registro local nunca debe detener el robot. } } }