NLogger.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #if DOTNET
  2. using System;
  3. using System.IO;
  4. using NLog;
  5. namespace ET
  6. {
  7. [Invoke]
  8. public class LogInvoker_NLog: AInvokeHandler<LogInvoker, ILog>
  9. {
  10. public override ILog Handle(LogInvoker args)
  11. {
  12. return new NLogger(args.SceneName, args.Process, args.Fiber);
  13. }
  14. }
  15. public class NLogger: ILog
  16. {
  17. private readonly NLog.Logger logger;
  18. static NLogger()
  19. {
  20. LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration("Packages/cn.etetet.loader/Scripts/Loader/Server/NLog.config");
  21. LogManager.Configuration.Variables["currentDir"] = Environment.CurrentDirectory;
  22. }
  23. public NLogger(string name, int process, int fiber)
  24. {
  25. this.logger = LogManager.GetLogger($"{(uint)process:000000}.{(uint)fiber:0000000000}.{name}");
  26. }
  27. public void Trace(string message)
  28. {
  29. this.logger.Trace(message);
  30. }
  31. public void Warning(string message)
  32. {
  33. this.logger.Warn(message);
  34. }
  35. public void Info(string message)
  36. {
  37. this.logger.Info(message);
  38. }
  39. public void Debug(string message)
  40. {
  41. this.logger.Debug(message);
  42. }
  43. public void Error(string message)
  44. {
  45. this.logger.Error(message);
  46. }
  47. public void Error(Exception e)
  48. {
  49. this.logger.Error(e.ToString());
  50. }
  51. public void Trace(ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message)
  52. {
  53. this.logger.Trace(message.ToStringAndClear());
  54. }
  55. public void Warning(ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message)
  56. {
  57. this.logger.Warn(message.ToStringAndClear());
  58. }
  59. public void Info(ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message)
  60. {
  61. this.logger.Info(message.ToStringAndClear());
  62. }
  63. public void Debug(ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message)
  64. {
  65. this.logger.Debug(message.ToStringAndClear());
  66. }
  67. public void Error(ref System.Runtime.CompilerServices.DefaultInterpolatedStringHandler message)
  68. {
  69. this.logger.Error(message.ToStringAndClear());
  70. }
  71. }
  72. }
  73. #endif