using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace SchedulerTool { /// /// Class to write a log in schedulerlog.txt file on applicaiton startup path /// public static class LogWriter { public static void LogInfo(string message,string methodName) { try { string path = $"{Application.StartupPath}\\Logs\\{DateTime.Now.ToString("MMyyyy")}"; if(!Directory.Exists(path)) { Directory.CreateDirectory(path); } path = $"{path}\\SchedulerLog.txt"; if (!File.Exists(path)) { File.Create(path).Dispose(); } using (StreamWriter w = File.AppendText(path)) { Log(message,methodName, w); } } catch (Exception ex) { //throw; } } private static void Log(string logMessage,string methodName, TextWriter txtWriter) { try { txtWriter.Write("\r\n"); txtWriter.WriteLine($"Method Name:{methodName}"); txtWriter.WriteLine($"Log Date Time:{DateTime.Now}"); txtWriter.WriteLine($"Info:{logMessage}"); txtWriter.WriteLine("-------------------------------------------------------------------------------------------------------"); } catch (Exception ex) { } } } }