LogTool.cs 1013 B

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using System.Text;
  6. namespace MAutoUpdate
  7. {
  8. public static class LogTool
  9. {
  10. static string temp = AppDomain.CurrentDomain.BaseDirectory + "/logs";
  11. public static void AddLog(String value)
  12. {
  13. try
  14. {
  15. Debug.WriteLine(value);
  16. if (Directory.Exists(Path.Combine(temp, @"update\")) == false)
  17. {
  18. DirectoryInfo directoryInfo = new DirectoryInfo(Path.Combine(temp, @"update\"));
  19. directoryInfo.Create();
  20. }
  21. using (StreamWriter sw = File.AppendText(Path.Combine(temp, @"update\update.log")))
  22. {
  23. sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  24. sw.WriteLine(value);
  25. sw.WriteLine();
  26. }
  27. }
  28. catch
  29. {
  30. }
  31. }
  32. }
  33. }