Logger.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System.Threading;
  2. namespace Flyinsono.Client.Test
  3. {
  4. public class Logger
  5. {
  6. private static LogEngine _logEngine;
  7. private static string _accountName;
  8. public static bool Debug { get; set; }
  9. public static void RegisterEngine(LogEngine logEngine)
  10. {
  11. _logEngine = logEngine;
  12. }
  13. public static void WriteLineInfo(string msg)
  14. {
  15. _logEngine?.Write(LogLevel.Info, "[Thread:" + Thread.CurrentThread.ManagedThreadId.ToString() + "]" + msg);
  16. }
  17. public static void WriteLineWarn(string msg)
  18. {
  19. _logEngine?.Write(LogLevel.Warn, "[Thread:" + Thread.CurrentThread.ManagedThreadId.ToString() + "]" + msg);
  20. }
  21. public static void WriteLineError(string msg)
  22. {
  23. _logEngine?.Write(LogLevel.Error, "[Thread:" + Thread.CurrentThread.ManagedThreadId.ToString() + "]" + msg);
  24. }
  25. public static void WriteUserOperationLog(string msg, string accountName="")
  26. {
  27. if (string.IsNullOrEmpty(_accountName)&&!string.IsNullOrEmpty(accountName))
  28. {
  29. _accountName=accountName;
  30. }
  31. _logEngine?.Write(LogLevel.UserOperation, _accountName+":->"+msg);
  32. }
  33. public static void WriteLineVerbose(string msg)
  34. {
  35. #if DEBUG
  36. _logEngine?.Write(LogLevel.Verbose, "[Thread:" + Thread.CurrentThread.ManagedThreadId.ToString() + "]" + msg);
  37. #endif
  38. }
  39. public static void WriteLineDebug(string msg)
  40. {
  41. #if DEBUG
  42. _logEngine?.Write(LogLevel.Debug, "[Thread:" + Thread.CurrentThread.ManagedThreadId.ToString() + "]" + msg);
  43. #endif
  44. }
  45. }
  46. }