CommonHandleClass.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6. namespace Senparc.Weixin.MP.Sample.CommonService
  7. {
  8. /// <summary>
  9. /// 常用处理类
  10. /// </summary>
  11. public class CommonHandleClass
  12. {
  13. public CommonHandleClass() {
  14. }
  15. /// <summary>
  16. /// 微信接口日志目录路径
  17. /// </summary>
  18. public static string WeiXinlogsPath {
  19. get { return LYFZ.WinAPI.CustomPublicMethod.BasePath + "\\Logs\\WeiXinlogs\\"; }
  20. }
  21. /// <summary>
  22. /// 写日志(用于跟踪)
  23. /// </summary>
  24. public static void WriteLog(string strMemo)
  25. {
  26. string filename = LYFZ.WinAPI.CustomPublicMethod.BasePath + "\\Logs\\WeiXinlogs.txt";
  27. if (!Directory.Exists(System.IO.Path.GetDirectoryName(filename)))
  28. Directory.CreateDirectory(System.IO.Path.GetDirectoryName(filename));
  29. StreamWriter sr = null;
  30. try
  31. {
  32. if (!File.Exists(filename))
  33. {
  34. sr = File.CreateText(filename);
  35. }
  36. else
  37. {
  38. sr = File.AppendText(filename);
  39. }
  40. sr.WriteLine(strMemo);
  41. }
  42. catch
  43. {
  44. }
  45. finally
  46. {
  47. if (sr != null)
  48. sr.Close();
  49. }
  50. }
  51. }
  52. }