You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

41 lines
1.5 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace HBLConsole.Service
  8. {
  9. public class TextHelper
  10. {
  11. private volatile static TextHelper _Instance;
  12. public static TextHelper GetInstance => _Instance ?? (_Instance = new TextHelper());
  13. private TextHelper() { }
  14. /// <summary>
  15. /// 保存日志信息
  16. /// </summary>
  17. /// <param name="info"></param>
  18. public void SaveLogInfo(string info, string name)
  19. {
  20. if (info?.Length > 0)
  21. {
  22. Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AccessFile\\OrderInfoLog"));
  23. string path = $"{AppDomain.CurrentDomain.BaseDirectory}AccessFile\\OrderInfoLog\\{DateTime.Now.ToString("yyyy-MM-dd") + " " + name}.txt";
  24. StringBuilder sb = new StringBuilder();
  25. sb.Append($"****************************************** {DateTime.Now} ******************************************" + "\n");
  26. sb.Append(info);
  27. sb.Append("**********************************************************************************************************" + "\n\n");
  28. FileStream fs = new FileStream($"{path}", FileMode.Append);
  29. StreamWriter sw = new StreamWriter(fs);
  30. sw.WriteLine(sb.ToString());
  31. sw.Close();
  32. fs.Close();
  33. }
  34. }
  35. }
  36. }