FileRrecordService.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 ST_CUBE_MES.Service
  8. {
  9. public class FileRrecordService
  10. {
  11. private static string LogFolder = "Log";
  12. //private string serialNumber;
  13. private string fileName;
  14. private string FilePath
  15. {
  16. get
  17. {
  18. if (string.IsNullOrEmpty(fileName))
  19. {
  20. return null;
  21. }
  22. return Path.Combine(Directory.GetCurrentDirectory(), LogFolder, fileName);
  23. }
  24. }
  25. public void Start(string serialNumber)
  26. {
  27. fileName = String.Format("{0}_{1}.txt", serialNumber, DateTime.Now.ToString("yyyyMMddHHmmss"));
  28. //MessageBox.Show(FilePath);
  29. //File.Create(FilePath);
  30. }
  31. public void Log(string logString)
  32. {
  33. if (string.IsNullOrEmpty(fileName))
  34. {
  35. return;
  36. }
  37. logString += Environment.NewLine;
  38. File.AppendAllText(FilePath, logString);
  39. }
  40. public void Complete()
  41. {
  42. fileName = null;
  43. }
  44. }
  45. }