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

Extension method support for Microsoft.Extensions.Logging.ILogger? #23

Closed
zolrath opened this issue Jul 10, 2018 · 7 comments
Closed

Extension method support for Microsoft.Extensions.Logging.ILogger? #23

zolrath opened this issue Jul 10, 2018 · 7 comments

Comments

@zolrath
Copy link

zolrath commented Jul 10, 2018

Hi!
Great library I really appreciate the ease of timing blocks of code with a simple using!
I'm currently using .net core dependency injection and their ILogger interface with Serilog registered to it.

When I try to use the _logger.TimeOperation("Processing {recordId}", id) syntax I am greeted with:
Cannot convert instance argument type 'Microsoft.Extensions.Logging.ILogger' to 'Serilog.ILogger'
or
Cannot convert instance argument type 'Microsoft.Extensions.Logging.ILogger<MyClassContext>' to 'Serilog.ILogger'

I am using the Operation.Time method at the moment but this loses the SourceContext that has been set up on my logger during injection.

Any chance the extension methods could be enhanced to support the Microsoft ILogger? Operation and the CompletionBehavior enum are internal so I cannot simply drop a new extension method in my project.

Thanks!

@nblumhardt
Copy link
Owner

Hi - thanks for the suggestion! No, support for MEL would be great in a separate library, but the plan for this one is to stay Serilog-specific. Cheers!

@dropsonic
Copy link

@nblumhardt does such library exist? How should I properly use SerilogTimings with ILogger<T> from Microsoft.Extensions.Logging injected via DI?

@nblumhardt
Copy link
Owner

Hi @dropsonic - I'm not aware of anyone having published one, but I haven't searched carefully. As things stand, you need to use Serilog's logging interfaces with this library.

@bakester14
Copy link

@sveins12
Copy link

@zolrath Did you find a solution to this?

@ivandamyanov
Copy link

@sveins12 What I found is this small package, says it is "This project is a port of Serilog Timings":
https://github.com/eltoncezar/LoggingTimings
First time I'm trying it out too, just letting you know.

@ogulcanturan
Copy link

@sveins12, @ivandamyanov I created a library that support for Microsoft.Extensions.Logging.ILogger couple years ago, and published to public (8 months ago). It is an adaptation of Serilog Timings.

https://github.com/ogulcanturan/Ogu.Extensions.Logging.Timings

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

No branches or pull requests

7 participants