Logs.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. }
  39. }