OCPPLogFactory.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. 
  2. using SuperSocket.SocketBase;
  3. using SuperSocket.SocketBase.Logging;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace OCPPServer.SubProtocol
  11. {
  12. /// <summary>
  13. /// OCPP log factory
  14. /// </summary>
  15. public class OCPPLogFactory : LogFactoryBase
  16. {
  17. public OCPPLogFactory()
  18. : this("NLog.config")
  19. {
  20. }
  21. public OCPPLogFactory(string log4netConfig)
  22. : base(log4netConfig)
  23. {
  24. List<string> configlist = new List<string>();
  25. configlist.Add(ConfigFile);
  26. NLog.Config.XmlLoggingConfiguration.SetCandidateConfigFilePaths(configlist);
  27. }
  28. /// <summary>
  29. /// Gets the config file file path.
  30. /// </summary>
  31. //protected string ConfigFile { get; private set; }
  32. //public OCPPLogFactory()
  33. //{
  34. // string configFile = "NLog.config";
  35. // var currentAppDomain = AppDomain.CurrentDomain;
  36. // var isolation = IsolationMode.None;
  37. // var isolationValue = currentAppDomain.GetData(typeof(IsolationMode).Name);
  38. // if (isolationValue != null)
  39. // isolation = (IsolationMode)isolationValue;
  40. // if (isolation == IsolationMode.None)
  41. // {
  42. // var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, configFile);
  43. // if (File.Exists(filePath))
  44. // {
  45. // ConfigFile = filePath;
  46. // return;
  47. // }
  48. // filePath = Path.Combine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config"), configFile);
  49. // if (File.Exists(filePath))
  50. // {
  51. // ConfigFile = filePath;
  52. // return;
  53. // }
  54. // ConfigFile = configFile;
  55. // List<string> configlist = new List<string>();
  56. // configlist.Add(ConfigFile);
  57. // NLog.Config.XmlLoggingConfiguration.SetCandidateConfigFilePaths(configlist);
  58. // return;
  59. // }
  60. //}
  61. /// <summary>
  62. /// Gets the log by name.
  63. /// </summary>
  64. /// <param name="name">The name.</param>
  65. /// <returns></returns>
  66. /// <summary>
  67. /// Gets the log by name.
  68. /// </summary>
  69. /// <param name="name">The name.</param>
  70. /// <returns></returns>
  71. ///
  72. //public override ILog GetLog(string name)
  73. //{
  74. // NLog.ILogger logger = NLog.LogManager.GetCurrentClassLogger();
  75. // //return new ConsoleLog(name);
  76. // ILog log = logger as Log4NetLog;
  77. // return new Log4NetLog(LogManager.GetLogger(name)); ;
  78. //}
  79. public override SuperSocket.SocketBase.Logging.ILog GetLog(string name)
  80. {
  81. return new OCPPLog(name);
  82. }
  83. }
  84. }