LoggerFactory.cs 1.8 KB

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