Log.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace ShakerService.Tools
  7. {
  8. internal class Log
  9. {
  10. log4net.ILog log;
  11. private Log()
  12. {
  13. log = log4net.LogManager.GetLogger(typeof(Service));
  14. }
  15. static Log()
  16. {
  17. }
  18. public void Info(string msg)
  19. {
  20. log.Info($"{DateTime.Now}:{msg}");
  21. Debug(msg);
  22. }
  23. public void Debug(string msg)
  24. {
  25. #if DEBUG
  26. log.Debug($"{DateTime.Now}:{msg}");
  27. if(System.Console.IsOutputRedirected)
  28. {
  29. System.Diagnostics.Debug.WriteLine($"{DateTime.Now}:{msg}");
  30. }
  31. else
  32. {
  33. Console.WriteLine($"{DateTime.Now}:{msg}");
  34. }
  35. #endif
  36. }
  37. public void Error(string msg)
  38. {
  39. log.Error($"{DateTime.Now}:{msg}");
  40. Debug(msg);
  41. }
  42. public static Log Default { get; } = new Log();
  43. }
  44. }