// METHOD HEADER COMMENT ------------------------------------------------------------------------------- /** * \fn static public bool AppendLogFile() * \brief Writes new logs into a file * \details This writes individual logs into the file specified by the loggerPath variable. * If there is an error, it throws an exception to a new log. * \exception From FileStream and StreamWriter * \see LogIt() * \return bool appendSuccess A value indicating whether the file write threw an exception. * * ---------------------------------------------------------------------------------------------------- */ static public bool AppendLogFile(TMSLog newLog) { bool appendSuccess = true; LoggerPath = Environment.CurrentDirectory; try { /// Open the filestream to append to the file. FileStream fileStream = new FileStream((LoggerPath + "/TMSLogger.txt"), FileMode.Append, FileAccess.Write); StreamWriter fileWriter = new StreamWriter(fileStream); /// Add each log entry from the working list to the file as a BSV fileWriter.WriteLine(newLog.BSV); fileWriter.Flush(); /// Close the file fileWriter.Close(); fileStream.Close(); } /// If an exception is thrown here, catch it catch (Exception e) { /// This could become problematic as it calls itself LogIt("|" + LoggerPath + "/AdminClasses.cs" + "|" + "TMSLogger" + "|" + "AppendLogFile" + "|" + "Exception" + "|" + e.Message + "|"); appendSuccess = false; } return(appendSuccess); }
static public List <TMSLog> logs = new List <TMSLog>(); /// This is a list of logs stored locally // METHOD HEADER COMMENT ------------------------------------------------------------------------------- /** * \fn static public void LogIt(string newLogString) * \brief This creates a new log object * \details This creates a new log object, adds it to the local list, then appends it to the * external file * \param[in] string newLogString This is the unparsed BSV string to create the file. * \see TMSLog(), logs.Add(), AppendLogFile() * \return void * * ---------------------------------------------------------------------------------------------------- */ static public void LogIt(string newLogString) { TMSLog myLog = new TMSLog(newLogString); logs.Add(myLog); if (AppendLogFile(myLog) == false) { /// Error writing to Log File: Try once again AppendLogFile(myLog); } ; }
// METHOD HEADER COMMENT ------------------------------------------------------------------------------- /** * \fn static public void NewLog(string newLogString) * \brief This creates a new log object * \details This creates a new log object, and adds it to the local list. This exists so that the * function ReadExistingLogFile doesn't call recursively. * \param[in] string newLogString This is the unparsed BSV string to create the file. * \see TMSLog(), logs.Add() * \return void * * ---------------------------------------------------------------------------------------------------- */ static public void NewLog(string newLogString) { TMSLog myLog = new TMSLog(newLogString); logs.Add(myLog); }
public void LogStatusEventHandler(TMSLog log) { // Handle the event (send it to the status bar) status.Text = "Status: " + log.logMessage; }