Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added NLogLoggerFactory #135

Merged
merged 1 commit into from
Sep 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions src/NLog.Extensions.Logging/NLogLoggerFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using Microsoft.Extensions.Logging;
using NLog.Common;

namespace NLog.Extensions.Logging
{
/// <summary>
/// Creating DI loggers for Microsoft.Extensions.Logging and NLog
/// </summary>
public class NLogLoggerFactory : ILoggerFactory
{
private NLogLoggerProvider _provider;

/// <summary>
/// New factory with default options
/// </summary>
public NLogLoggerFactory()
{
_provider = new NLogLoggerProvider();
}

/// <summary>
/// New factory with options.
/// </summary>
/// <param name="options"></param>
public NLogLoggerFactory(NLogProviderOptions options)
{
_provider = new NLogLoggerProvider(options);
}


#region Implementation of IDisposable

/// <summary>
/// Dispose
/// </summary>
public void Dispose()
{
LogManager.Flush();
}

#endregion

#region Implementation of ILoggerFactory

/// <summary>
/// Creates a new <see cref="T:Microsoft.Extensions.Logging.ILogger" /> instance.
/// </summary>
/// <param name="categoryName">The logger name for messages produced by the logger.</param>
/// <returns>The <see cref="T:Microsoft.Extensions.Logging.ILogger" />.</returns>
public Microsoft.Extensions.Logging.ILogger CreateLogger(string categoryName)
{
return _provider.CreateLogger(categoryName);
}

/// <summary>
/// Do nothing
/// </summary>
/// <param name="provider">The <see cref="T:Microsoft.Extensions.Logging.ILoggerProvider" />.</param>
public void AddProvider(ILoggerProvider provider)
{
InternalLogger.Debug("AddProvider will be ignored");
}

#endregion
}
}
4 changes: 2 additions & 2 deletions src/NLog.Extensions.Logging/NLogLoggerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ public class NLogLoggerProvider : Microsoft.Extensions.Logging.ILoggerProvider
public NLogProviderOptions Options { get; set; }

/// <summary>
/// <see cref="NLogLoggerProvider"/> with default options.
/// New provider with default options, see <see cref="Options"/>
/// </summary>
public NLogLoggerProvider()
{
}

/// <summary>
/// <see cref="NLogLoggerProvider"/> with default options.
/// New provider with options
/// </summary>
/// <param name="options"></param>
public NLogLoggerProvider(NLogProviderOptions options)
Expand Down