Logs.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System;
  2. using System.IO;
  3. using System.Windows.Forms;
  4. namespace StageController
  5. {
  6. public class Logs
  7. {
  8. private static string m_filePath = Application.StartupPath + "\\Logs\\";
  9. private static void chkFile()
  10. {
  11. if (!Directory.Exists(m_filePath))
  12. {
  13. Directory.CreateDirectory(m_filePath); //不存在就创建目录
  14. }
  15. }
  16. public static void Write(string str)
  17. {
  18. try
  19. {
  20. #if DEBUG
  21. {
  22. str = DateTime.Now.ToString("HH:mm:ss:fff") + ":" + str;
  23. chkFile();
  24. StreamWriter sw = File.AppendText(m_filePath + DateTime.Now.ToString("yyyyMMdd") + ".txt");
  25. //开始写入
  26. sw.WriteLine(str);
  27. //清空缓冲区
  28. sw.Flush();
  29. //关闭流
  30. sw.Close();
  31. }
  32. #endif
  33. }
  34. catch (Exception)
  35. {
  36. }
  37. }
  38. //Add by shayg 20220718 start
  39. public static void WriteFocus(string str)
  40. {
  41. try
  42. {
  43. #if DEBUG
  44. {
  45. str = DateTime.Now.ToString("HH:mm:ss:fff") + ":" + str;
  46. chkFile();
  47. StreamWriter sw = File.AppendText(m_filePath + DateTime.Now.ToString("yyyyMMdd") + "_Focus.txt");
  48. sw.WriteLine(str);
  49. sw.Flush();
  50. sw.Close();
  51. }
  52. #endif
  53. }
  54. catch (Exception)
  55. {
  56. }
  57. }
  58. //Add by shayg 20220718 end
  59. }
  60. }