Skip to content

Question/Discussion: Why was 'SerilogLoggerFactory' implemented? #183

Closed
@julealgon

Description

@julealgon

As I dig deeper and deeper into the logging infrastructure from Microsoft.Extensions.Logging, I end up finding more stuff that puzzles me about the way Serilog integrates with it.

I've now realized that Serilog has it's own implementation of ILoggerFactory, even though Microsoft's recommended approach for implementing custom loggers is to implement ILoggerProvider only.

I'd like to understand why the team decided to create a custom ILoggerFactory implementation that replaces the one from Microsoft.Extensions. As a result, the Serilog API becomes unwieldy, having multiple registration methods each doing a different registration approach: one adds a custom ILoggerProvider, another adds a custom ILoggerFactory which completely ignores the providers, etc.

I only realized this after consuming ILogger<T> explicitly in one of my classes and realizing it wasn't logging anything, even though the request logging on the API was working fine and writing to the console... turned out I was using AddSerilog on the ILoggerBuilder, which replaces the ILoggerProviders but keeps the original ILoggerFactory. Due to a misunderstanding on my part, I had removed the logger configuration flags from my appsettings.config file, which appear to be read by the original factory implementation. On the other hand, the request logging uses Serilog's ILogger directly and completely bypasses Microsoft.Extensions, which is why it was working in my scenario.

I understand this may sound like a weird question, but I'm just frustrated as a consumer of the library to always stumble upon these weird registration quirks on every project I leverage Serilog. The more I find out about them, the more I want to stay away from them to be honest and rely as much as I can on the significantly cleaner Microsoft.Extensions interfaces. As a consumer, it seems like Serilog want's to purposefully create integrations that encourage people not to use Microsoft's standard interface. I just don't quite understand that approach, do you think the native interface is flawed in any way that would justify this approach?

Sorry about the rant... please take that as negative feedback from me from a user experience point of view (even being a fan of Serilog as a library).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions