From ba1126bd7ea75d79bc4553cf50ee958c80b0c3b6 Mon Sep 17 00:00:00 2001
From: Julian Verdurmen <304NotModified@users.noreply.github.com>
Date: Fri, 29 Sep 2017 22:23:25 +0200
Subject: [PATCH] Added NLogLoggerFactory
---
.../NLogLoggerFactory.cs | 67 +++++++++++++++++++
.../NLogLoggerProvider.cs | 4 +-
2 files changed, 69 insertions(+), 2 deletions(-)
create mode 100644 src/NLog.Extensions.Logging/NLogLoggerFactory.cs
diff --git a/src/NLog.Extensions.Logging/NLogLoggerFactory.cs b/src/NLog.Extensions.Logging/NLogLoggerFactory.cs
new file mode 100644
index 00000000..56b38b66
--- /dev/null
+++ b/src/NLog.Extensions.Logging/NLogLoggerFactory.cs
@@ -0,0 +1,67 @@
+using System;
+using Microsoft.Extensions.Logging;
+using NLog.Common;
+
+namespace NLog.Extensions.Logging
+{
+ ///
+ /// Creating DI loggers for Microsoft.Extensions.Logging and NLog
+ ///
+ public class NLogLoggerFactory : ILoggerFactory
+ {
+ private NLogLoggerProvider _provider;
+
+ ///
+ /// New factory with default options
+ ///
+ public NLogLoggerFactory()
+ {
+ _provider = new NLogLoggerProvider();
+ }
+
+ ///
+ /// New factory with options.
+ ///
+ ///
+ public NLogLoggerFactory(NLogProviderOptions options)
+ {
+ _provider = new NLogLoggerProvider(options);
+ }
+
+
+ #region Implementation of IDisposable
+
+ ///
+ /// Dispose
+ ///
+ public void Dispose()
+ {
+ LogManager.Flush();
+ }
+
+ #endregion
+
+ #region Implementation of ILoggerFactory
+
+ ///
+ /// Creates a new instance.
+ ///
+ /// The logger name for messages produced by the logger.
+ /// The .
+ public Microsoft.Extensions.Logging.ILogger CreateLogger(string categoryName)
+ {
+ return _provider.CreateLogger(categoryName);
+ }
+
+ ///
+ /// Do nothing
+ ///
+ /// The .
+ public void AddProvider(ILoggerProvider provider)
+ {
+ InternalLogger.Debug("AddProvider will be ignored");
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file
diff --git a/src/NLog.Extensions.Logging/NLogLoggerProvider.cs b/src/NLog.Extensions.Logging/NLogLoggerProvider.cs
index 095ce22c..46438e1f 100644
--- a/src/NLog.Extensions.Logging/NLogLoggerProvider.cs
+++ b/src/NLog.Extensions.Logging/NLogLoggerProvider.cs
@@ -11,14 +11,14 @@ public class NLogLoggerProvider : Microsoft.Extensions.Logging.ILoggerProvider
public NLogProviderOptions Options { get; set; }
///
- /// with default options.
+ /// New provider with default options, see
///
public NLogLoggerProvider()
{
}
///
- /// with default options.
+ /// New provider with options
///
///
public NLogLoggerProvider(NLogProviderOptions options)