LogerHelper.cs 1.3 KB

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