Log program activity

public void LogActivity(string ActivityText, bool IsError = null)
{
 System.DateTime TimeNow = Now;
 ActivityLogRichTextBox.SelectionColor = Color.DarkBlue;
 ActivityLogRichTextBox.AppendText(ControlChars.CrLf + TimeNow.ToString("ddd yyyy-MM-dd hh:mm:ss.fff"));
 ActivityLogRichTextBox.SelectionColor = Color.Black;
 if (IsError != null) {
  if (IsError == true) {
   ActivityLogRichTextBox.SelectionColor = Color.Red;
  }
 }
 ActivityLogRichTextBox.AppendText(" " + ActivityText + ControlChars.CrLf);
 ActivityLogRichTextBox.ScrollToCaret();
 string LastWeeksLogFile = Application.ExecutablePath + ".ActivityLog." + TimeNow.AddDays(1).ToString("ddd") + ".txt";
 if (My.Computer.FileSystem.FileExists(LastWeeksLogFile)) {
  My.Computer.FileSystem.DeleteFile(LastWeeksLogFile, FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently);
 }
 My.Computer.FileSystem.WriteAllText(Application.ExecutablePath + ".ActivityLog." + TimeNow.ToString("ddd") + ".txt", ControlChars.CrLf + TimeNow.ToString("ddd yyyy-MM-dd hh:mm:ss.fff") + " " + ActivityText + ControlChars.CrLf, true);
 Application.DoEvents();
}

No comments:

Post a Comment