using System; using System.IO; using System.Text; using System.Threading.Tasks; namespace EthermineBotTelegramCore { public static class Logger { private static string fullLogPath = AppSettings.fullLogPath; private static string errorLogPath = AppSettings.errorLogPath; static FileStream fullLog = new FileStream(fullLogPath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None, 4096, FileOptions.Asynchronous | FileOptions.SequentialScan); static FileStream errLog = new FileStream(errorLogPath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None, 4096, FileOptions.Asynchronous | FileOptions.SequentialScan); static Logger() { fullLog.Seek(0,SeekOrigin.End); errLog.Seek(0,SeekOrigin.End); } public async static Task LogInfo(string message) { message = $"{DateTime.Now.ToLocalTime().ToString("[MM-dd-yyyy HH:mm:ss]")} INFO {message} \n"; byte[] logLine = Encoding.Unicode.GetBytes(message); await fullLog.WriteAsync(logLine, 0, logLine.Length); await fullLog.FlushAsync(); } public async static Task LogWarn(string message) { message = $"{DateTime.Now.ToLocalTime().ToString("[MM-dd-yyyy HH:mm:ss]")} WARNING {message} \n"; byte[] logLine = Encoding.Unicode.GetBytes(message); await fullLog.WriteAsync(logLine, 0, logLine.Length); await fullLog.FlushAsync(); } public async static Task LogError(string message) { message = $"{DateTime.Now.ToLocalTime().ToString("[MM-dd-yyyy HH:mm:ss]")} ERROR {message} \n"; byte[] logLine = Encoding.Unicode.GetBytes(message); await fullLog.WriteAsync(logLine, 0, logLine.Length); await errLog.WriteAsync(logLine, 0, logLine.Length); await fullLog.FlushAsync(); await errLog.FlushAsync(); } public async static Task LogDebug(string message) { message = $"{DateTime.Now.ToLocalTime().ToString("[MM-dd-yyyy HH:mm:ss]")} DEBUG {message} \n"; byte[] logLine = Encoding.Unicode.GetBytes(message); await fullLog.WriteAsync(logLine, 0, logLine.Length); await fullLog.FlushAsync(); } public static void Stop() { fullLog.Close(); errLog.Close(); } public async static Task Save() { await fullLog.FlushAsync(); await errLog.FlushAsync(); } } }