Skip to content

Expose SerilogLoggerFactory #19

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

Merged
merged 3 commits into from
Dec 17, 2017
Merged
Changes from 2 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
33 changes: 28 additions & 5 deletions src/Serilog.AspNetCore/AspNetCore/SerilogLoggerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,49 @@

namespace Serilog.AspNetCore
{
class SerilogLoggerFactory : ILoggerFactory
/// <summary>
/// Implements Microsoft's ILoggerFactory so that we can inject Serilog Logger.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of Microsoft's ILoggerFactory we could use <see cref="ILoggerFactory"/>

/// </summary>
/// <seealso cref="Microsoft.Extensions.Logging.ILoggerFactory" />
public class SerilogLoggerFactory : ILoggerFactory
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation is funny here and below - may need to use spaces, rather than tabs?

{
readonly SerilogLoggerProvider _provider;

public SerilogLoggerFactory(Serilog.ILogger logger = null, bool dispose = false)
/// <summary>
/// Initializes a new instance of the <see cref="SerilogLoggerFactory"/> class.
/// </summary>
/// <param name="logger">The logger.</param>
/// <param name="dispose">if set to <c>true</c> [dispose].</param>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public SerilogLoggerFactory(Serilog.ILogger logger = null, bool dispose = false)
{
_provider = new SerilogLoggerProvider(logger, dispose);
}

public void Dispose()
/// <summary>
/// Disposes the provider.
/// </summary>
public void Dispose()
{
_provider.Dispose();
}

public Microsoft.Extensions.Logging.ILogger CreateLogger(string categoryName)
/// <summary>
/// Creates a new <see cref="T:Microsoft.Extensions.Logging.ILogger" /> instance.
/// </summary>
/// <param name="categoryName">The category 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);
}

public void AddProvider(ILoggerProvider provider)
/// <summary>
/// Adds an <see cref="T:Microsoft.Extensions.Logging.ILoggerProvider" /> to the logging system.
/// </summary>
/// <param name="provider">The <see cref="T:Microsoft.Extensions.Logging.ILoggerProvider" />.</param>
public void AddProvider(ILoggerProvider provider)
{
SelfLog.WriteLine("Ignoring added logger provider {0}", provider);
}
Expand Down