LogManager.cs 2.4 KB

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