Keine Beschreibung

LogInterface.cs 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. 
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. namespace CallCenter.Utility.log
  8. {
  9. public class LogInterface
  10. {
  11. //心连心接口调用 日志
  12. public static void WriteLog(string strLog)
  13. {
  14. //string sFilePath = System.Web.HttpContext.Current.Server.MapPath("\\Log\\" + DateTime.Now.ToString("yyyyMM"));
  15. string sFilePath = "D:\\CallCenter_log\\LogInterface\\" + DateTime.Now.ToString("yyyy-MM");
  16. string sFileName = "" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
  17. sFileName = sFilePath + "\\" + sFileName; //文件的绝对路径
  18. if (!Directory.Exists(sFilePath))//验证路径是否存在
  19. {
  20. Directory.CreateDirectory(sFilePath);
  21. //不存在则创建
  22. }
  23. FileStream fs;
  24. StreamWriter sw;
  25. if (File.Exists(sFileName))
  26. //验证文件是否存在,有则追加,无则创建
  27. {
  28. fs = new FileStream(sFileName, FileMode.Append, FileAccess.Write);
  29. }
  30. else
  31. {
  32. fs = new FileStream(sFileName, FileMode.Create, FileAccess.Write);
  33. }
  34. sw = new StreamWriter(fs);
  35. sw.WriteLine("记录时间:[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "] -- " + RequestString.GetIP() + " " + strLog + "\r\n");
  36. sw.Close();
  37. fs.Close();
  38. }
  39. }
  40. }