LogHelper.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace Core.Mes.Client.Comm.Tool
  6. {
  7. public class LogHelper
  8. {
  9. #region 记录系统运行日志
  10. /// <summary>
  11. /// 写日志
  12. /// </summary>
  13. /// <param name="strModelName">模块名称</param>
  14. /// <param name="str">日志</param>
  15. public static void WriteLogs(string strModelName, string str)
  16. {
  17. try
  18. {
  19. string m_szRunPath = System.Environment.CurrentDirectory.ToString();
  20. string strLogPath = m_szRunPath + "\\log";
  21. if (!(System.IO.Directory.Exists(strLogPath)))
  22. {
  23. System.IO.Directory.CreateDirectory(strLogPath);
  24. }
  25. strLogPath = m_szRunPath + "\\log\\" + strModelName + "_" + System.DateTime.Now.ToString("yyyyMMddhh") + ".log";
  26. System.IO.TextWriter tw = new System.IO.StreamWriter(strLogPath, true);
  27. //tw.Encoding = new e
  28. tw.WriteLine(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  29. tw.WriteLine(str);
  30. tw.WriteLine("\r\n");
  31. tw.Close();
  32. tw.Dispose();
  33. }
  34. catch
  35. {
  36. //throw;
  37. }
  38. }
  39. #endregion
  40. }
  41. }