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

Expose SerilogLoggerFactory #19

merged 3 commits into from
Dec 17, 2017

Conversation

jonathansant
Copy link
Contributor

I needed to retrieve some configuration prior to registering the logger. UseSerilog is invoked before the Startup class. I sought to register the Factory manually but found out that is internal. I think that SerilogLoggerFactory is the main take away from this library and therefore exposing it would make it more flexible for those who don't want to use the extension methods.

jonathansant and others added 2 commits December 9, 2017 18:34
I needed to retrieve some configuration prior to registering the logger. `UseSerilog` is invoked before the `Startup` class. I sought to register the Factory manually but found out that is internal. I think that `SerilogLoggerFactory` is the main take away from this library and therefore exposing it would make it more flexible for those who don't want to use the extension methods.
@nblumhardt
Copy link
Member

Thanks for the PR, @jonathansant.

Does the alternative overload of UseSerilog(), which accepts a delegate, cover your scenario?

Best regards,
Nick

@jonathansant
Copy link
Contributor Author

Since all my startup logic is in the Startup class, I can ugly hack it using statics but it would be ideal if I kept all the startup logic in one place. What would help is an extension method for the IServiceCollection class and then I could put everything in the ConfigureServices method. I can create a pull request for that if you prefer.

@nblumhardt
Copy link
Member

Thanks for the reply. I think providing the factory type is fine 👍

Copy link
Member

@nblumhardt nblumhardt left a comment

Choose a reason for hiding this comment

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

Looks good, just minor nitpicks. Thanks!

/// Implements Microsoft's ILoggerFactory so that we can inject Serilog Logger.
/// </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?

@@ -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"/>

/// 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.

@nblumhardt nblumhardt merged commit 3198e00 into serilog:dev Dec 17, 2017
@nblumhardt
Copy link
Member

Thank you 👍

@nblumhardt nblumhardt mentioned this pull request Mar 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants