public Logger() { //Constructor if (State == loggerState.Stopped) { //check to see if the logs folder exists, if not create it //check the Arma2 root directory first if (System.IO.Directory.Exists("logs")) { logDir = Path.GetFullPath("logs/"); } else { logDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Arma2NETMySQL/logs/"); if (!System.IO.Directory.Exists(logDir)) { System.IO.Directory.CreateDirectory(logDir); } } //Setup file streams DateTime dateValue = new DateTime(); dateValue = DateTime.Now; string fullpath = Path.Combine(logDir, dateValue.ToString("MM-dd-yyyy_HH-mm-ss") + ".log"); fs = new FileStream(fullpath, FileMode.Append); sw = new StreamWriter(fs); state = loggerState.Started; } }
public static void Stop() { if (State == loggerState.Started) { try { sw.Flush(); sw.Close(); fs.Close(); state = loggerState.Stopped; } catch (Exception ex) { Console.WriteLine("EXCEPTION: An exception occured while stopping the logger.\n**\t{0}", ex.ToString()); } } }