using System; using System.IO; namespace HeuristicLab.Algorithms.GraphRouting.Utilities { public static class Logger { //public static void writeToLogFile(string logMessage) { // string strLogMessage = string.Empty; // string strLogFile = "LogFile.txt"; // StreamWriter swLog; // //strLogMessage = string.Format("{0}: {1}", DateTime.Now, logMessage); // strLogMessage = logMessage; // if (!File.Exists(strLogFile)) { // swLog = new StreamWriter(strLogFile); // } else { // swLog = File.AppendText(strLogFile); // } // swLog.WriteLine(strLogMessage); // swLog.WriteLine(); // swLog.Close(); //} static StreamWriter LogWriter; public static void LogToFile(string message) { try { if (!File.Exists("LogFile.txt")) { LogWriter = new StreamWriter("LogFile.txt"); } else { LogWriter = File.AppendText("LogFile.txt"); } LogWriter.WriteLine(message); LogWriter.Flush(); } catch (Exception) { } finally { if (LogWriter != null) { LogWriter.Close(); } } } } }