Minimist C# error-logging class


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  1. namespace Kyrathasoft.Dialogs.ErrLogging {
  2.  
  3. using System;
  4. using System.IO;
  5. using System.Windows.Forms;
  6.  
  7. class clsErrLog {
  8.  
  9. public clsErrLog() {
  10. //set default path for error log text file
  11. errLogPath = Path.GetDirectoryName(Application.ExecutablePath) + "\\errorLog.txt";
  12. }
  13.  
  14. public clsErrLog(string errTxt) {
  15. //set default path for error log text file
  16. errLogPath = Path.GetDirectoryName(Application.ExecutablePath) + "\\errorLog.txt";
  17. updateErrorLog(errTxt);
  18. }
  19.  
  20. public clsErrLog(string errTxt, string full_path) {
  21. errLogPath = full_path;
  22. updateErrorLog(errTxt);
  23. }
  24.  
  25. private string errLogPath;
  26.  
  27. public string ErrLogPath {
  28. get { return errLogPath; }
  29. set { errLogPath = value; }
  30. }
  31.  
  32. private void updateErrorLog(string errorText) {
  33. string msg = Environment.NewLine + Environment.NewLine;
  34. msg += DateTime.Now.ToString() + Environment.NewLine + errorText;
  35. File.AppendAllText(errLogPath, msg);
  36. }
  37.  
  38. }
  39.  
  40. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.