LoggerFactory.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using NLog;
  3. using NLog.Config;
  4. using Quadarax.Foundation.Core.Logging;
  5. using Quadarax.Foundation.Core.Object;
  6. using ILogger = Quadarax.Foundation.Core.Logging.ILogger;
  7. namespace Quadarax.Foundation.Core.NLog
  8. {
  9. public class LoggerFactory : Singleton<ILogger, LoggerFactory>, ILogger
  10. {
  11. public static string ConfigurationFileName { get; set; }
  12. public void Configure(string configurationFileName)
  13. {
  14. if (!string.IsNullOrEmpty(configurationFileName))
  15. {
  16. LogManager.Configuration = new XmlLoggingConfiguration(configurationFileName);
  17. var log = Instance.GetLogger(GetType());
  18. log.Log(LogSeverityEnum.Debug, $"NLOG initialized from configuration file '{configurationFileName}'");
  19. }
  20. }
  21. public ILog GetLogger(string loggerName)
  22. {
  23. return Instance.GetLogger(loggerName);
  24. }
  25. public ILog GetLogger(Type loggerForType)
  26. {
  27. return Instance.GetLogger(loggerForType);
  28. }
  29. ILog ILogger.GetLogger(string loggerName)
  30. {
  31. return new Logger(loggerName);
  32. }
  33. ILog ILogger.GetLogger(Type loggerForType)
  34. {
  35. return new Logger(loggerForType);
  36. }
  37. }
  38. }