public void StopTimer(string Message) { _timer.Stop(); Log(string.Format("Timer Stopped: {0}\r\n", DateTime.Now)); Log(string.Format("Duration: {0} Seconds\r\n", _timer.Duration.ToString())); Log(Message); }
public string AddLogEntry(string strLogEntryGUID, string strLogEntryName, string strComment) { if (strLogEntryGUID != ActiveGUID) { throw new Exception("Log Entry GUID Mismatch."); } string lf = String.Empty; if (strLogFileName.Length > 0) { lf = @"\" + strLogFileName + ".csv"; } else { lf = @"\DefaultAppLog.csv"; } string strFullLogPathName = AppDomain.CurrentDomain.BaseDirectory.ToString() + lf; string strtime = DateTime.Now.ToShortDateString() + ": " + DateTime.Now.ToShortTimeString(); hpt.Stop(); EndTicks = hpt.Duration; cumTime += EndTicks; // add to cum time elapsed StringBuilder sbLog = new StringBuilder(); sbLog.Append("Add Entry: "); sbLog.Append(","); sbLog.Append(strLogEntryGUID); sbLog.Append(","); sbLog.Append(strtime); sbLog.Append(","); sbLog.Append(strLogEntryName); sbLog.Append(","); sbLog.Append(strComment); sbLog.Append(","); string strIntElapsed = String.Empty; sbLog.Append(EndTicks.ToString()); // this event duration in sec sbLog.Append(","); strIntElapsed = cumTime.ToString(); hpt.Start(); sbLog.Append(strIntElapsed); sbLog.Append("\r\n"); try { FileInfo fi = new FileInfo(strFullLogPathName); FileStream sWriterAppend = fi.Open(FileMode.Append, FileAccess.Write, FileShare.ReadWrite); sWriterAppend.Write(Encoding.ASCII.GetBytes(sbLog.ToString()), 0, sbLog.Length); sWriterAppend.Flush(); sWriterAppend.Close(); sbLog = null; fi = null; sWriterAppend = null; } catch (Exception ex) { sbLog = null; return(ex.Message); } return(strLogEntryGUID); }