LogService.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using Log;
  2. namespace PLCIOPointTool.Services;
  3. public class LogService : ILog
  4. {
  5. private readonly IOutputService _outputService;
  6. private bool disposedValue;
  7. public LogService(IOutputService outputService)
  8. {
  9. _outputService= outputService;
  10. }
  11. public string? Directory => null;
  12. public string? FilePath => null;
  13. public bool Initialize(string fileName)
  14. {
  15. throw new NotImplementedException();
  16. }
  17. public bool Info(string message, DateTime? dateTime = null)
  18. {
  19. _outputService.Output($"[{DateTime.Now.ToString()}] Log->Info:{message}");
  20. return true;
  21. }
  22. public bool Debug(string message, DateTime? dateTime = null)
  23. {
  24. _outputService.Output($"[{DateTime.Now.ToString()}] Log->Debug:{message}");
  25. return true;
  26. }
  27. public bool Warning(string message, DateTime? dateTime = null)
  28. {
  29. _outputService.Output($"[{DateTime.Now.ToString()}] Log->Warning:{message}");
  30. return true;
  31. }
  32. public bool Error(string message, DateTime? dateTime = null)
  33. {
  34. _outputService.Output($"[{DateTime.Now.ToString()}] Log->Error:{message}");
  35. return true;
  36. }
  37. public bool Fatal(string message, DateTime? dateTime = null)
  38. {
  39. _outputService.Output($"[{DateTime.Now.ToString()}] Log->Fatal:{message}");
  40. return true;
  41. }
  42. protected virtual void Dispose(bool disposing)
  43. {
  44. if (!disposedValue)
  45. {
  46. if (disposing)
  47. {
  48. // TODO: dispose managed state (managed objects)
  49. }
  50. // TODO: free unmanaged resources (unmanaged objects) and override finalizer
  51. // TODO: set large fields to null
  52. disposedValue = true;
  53. }
  54. }
  55. // // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
  56. // ~LogService()
  57. // {
  58. // // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
  59. // Dispose(disposing: false);
  60. // }
  61. public void Dispose()
  62. {
  63. // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
  64. Dispose(disposing: true);
  65. GC.SuppressFinalize(this);
  66. }
  67. }