LoggerBase.cs 989 B

123456789101112131415161718192021222324252627282930313233343536
  1. using InABox.Core;
  2. namespace InABox.Logging;
  3. public abstract class LoggerBase
  4. {
  5. public LogType[] LogTypes = { LogType.Information, LogType.Query, LogType.Update, LogType.Error, LogType.Important };
  6. protected abstract void DoSend(string message);
  7. public virtual void Send(LogType logType, string user, string message, Guid transaction)
  8. {
  9. if (!LogTypes.Any(x => x == logType))
  10. return;
  11. var type = logType switch
  12. {
  13. LogType.Information => "INFO",
  14. LogType.Query => "READ",
  15. LogType.Update => "UPDATE",
  16. LogType.Error => "ERROR",
  17. LogType.Important => "IMPTNT",
  18. _ => "ERROR"
  19. };
  20. var msg = string.Format("{0:HH:mm:ss.fff} {1} {2} {3} {4}",
  21. DateTime.Now,
  22. transaction,
  23. type?.PadRight(6),
  24. (user ?? "").PadRight(12),
  25. message
  26. );
  27. DoSend(msg);
  28. }
  29. public virtual void Stop() { }
  30. }