LoggerFactory.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using Microsoft.Extensions.Logging;
  3. using NLog;
  4. using NLog.Config;
  5. using Quadarax.Foundation.Core.Logging;
  6. using Quadarax.Foundation.Core.Object;
  7. using ILogger = Quadarax.Foundation.Core.Logging.ILogger;
  8. using LogLevel = Microsoft.Extensions.Logging.LogLevel;
  9. namespace Quadarax.Foundation.Core.NLog
  10. {
  11. public class LoggerFactory : Singleton<ILogger, LoggerFactory>, ILogger
  12. {
  13. public static string ConfigurationFileName { get; set; }
  14. public void Configure(string configurationFileName)
  15. {
  16. if (!string.IsNullOrEmpty(configurationFileName))
  17. {
  18. LogManager.Configuration = new XmlLoggingConfiguration(configurationFileName);
  19. var log = Instance.GetLogger(GetType());
  20. log.Log(LogSeverityEnum.Debug, $"NLOG initialized from configuration file '{configurationFileName}'");
  21. }
  22. }
  23. public ILog GetLogger(string loggerName)
  24. {
  25. return Instance.GetLogger(loggerName);
  26. }
  27. public ILog GetLogger(Type loggerForType)
  28. {
  29. return Instance.GetLogger(loggerForType);
  30. }
  31. ILog ILogger.GetLogger(string loggerName)
  32. {
  33. return new Logger(loggerName);
  34. }
  35. ILog ILogger.GetLogger(Type loggerForType)
  36. {
  37. return new Logger(loggerForType);
  38. }
  39. public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
  40. {
  41. throw new NotImplementedException();
  42. }
  43. public bool IsEnabled(LogLevel logLevel)
  44. {
  45. throw new NotImplementedException();
  46. }
  47. public IDisposable BeginScope<TState>(TState state) where TState : notnull
  48. {
  49. throw new NotImplementedException();
  50. }
  51. }
  52. }