LogManager.cs 2.3 KB

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