LogManager.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using System.IO;
  3. using UAS_MES_NEW.Entity;
  4. namespace UAS_MES_NEW.PublicMethod
  5. {
  6. class LogManager
  7. {
  8. public static string LogAddress = SystemInf.LogFolder;
  9. /// <summary>
  10. /// 记录操作
  11. /// </summary>
  12. /// <param name="Message"></param>
  13. public static void DoLog(string Message)
  14. {
  15. try
  16. {
  17. StreamWriter sw = File.AppendText(LogAddress + DateTime.Now.ToString("yyyy-MM-dd") + ".txt");
  18. sw.WriteLine("\n【时间】" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\n");
  19. sw.WriteLine("【消息】" + Message + "\n");
  20. sw.WriteLine("---------------------------------------------------------------------------------------------------------------");
  21. sw.Close();
  22. }
  23. catch (Exception) { }
  24. }
  25. /// <summary>
  26. /// 记录操作和SQL
  27. /// </summary>
  28. /// <param name="Message"></param>
  29. /// <param name="SQL"></param>
  30. public static void DoLog(string Message, string SQL)
  31. {
  32. try
  33. {
  34. StreamWriter sw = File.AppendText(LogAddress + DateTime.Now.ToString("yyyy-MM-dd") + ".txt");
  35. sw.WriteLine("\n【时间】" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\n");
  36. sw.WriteLine("【消息】" + Message + "\n");
  37. sw.WriteLine("【SQL】" + SQL + "\n");
  38. sw.WriteLine("---------------------------------------------------------------------------------------------------------------");
  39. sw.Close();
  40. }
  41. catch (Exception) { }
  42. }
  43. /// <summary>
  44. /// 记录SQL
  45. /// </summary>
  46. /// <param name="SQL"></param>
  47. public static void DoSQLLog(string SQL)
  48. {
  49. try
  50. {
  51. StreamWriter sw = File.AppendText(LogAddress + DateTime.Now.ToString("yyyy-MM-dd") + ".txt");
  52. sw.WriteLine("\n【时间】" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\n");
  53. sw.WriteLine("【SQL】" + SQL + "\n");
  54. sw.WriteLine("---------------------------------------------------------------------------------------------------------------");
  55. sw.Close();
  56. }
  57. catch (Exception) { }
  58. }
  59. }
  60. }