LogerHelper.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. namespace EInk.Tools
  2. {
  3. public static class LogerHelper
  4. {
  5. public static void RecordLogTxt(string message)
  6. {
  7. string strPath;
  8. DateTime dt = DateTime.Now;
  9. try
  10. {
  11. strPath = Directory.GetCurrentDirectory() + "\\Log";
  12. if (Directory.Exists(strPath) == false)
  13. {
  14. Directory.CreateDirectory(strPath);
  15. }
  16. strPath = strPath + "\\" + dt.ToString("yyyy") + "\\" + dt.ToString("MM");
  17. if (Directory.Exists(strPath) == false)
  18. {
  19. Directory.CreateDirectory(strPath);
  20. }
  21. strPath = strPath + "\\" + dt.Year.ToString() + "-" + dt.Month.ToString() + "-" + dt.Day.ToString() + ".txt";
  22. StreamWriter FileWriter = new StreamWriter(strPath, true);
  23. FileWriter.WriteLine("[" + dt.ToString("yyyy-MM-dd HH:mm:ss") + "] " + message);
  24. FileWriter.Close();
  25. }
  26. catch (Exception ex)
  27. {
  28. string str = ex.Message.ToString();
  29. }
  30. }
  31. }
  32. }