nblumhardt / serilog-timings

Extends Serilog with support for timed operations
Apache License 2.0
218 stars 21 forks source link

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

Closed zolrath closed 6 years ago

zolrath commented 6 years ago

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 commented 6 years ago

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 commented 5 years ago

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

nblumhardt commented 5 years ago

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 commented 4 years ago

https://github.com/serilog/serilog-extensions-logging might work for your use case @dropsonic @zolrath

sveins12 commented 10 months ago

@zolrath Did you find a solution to this?

ivandamyanov commented 9 months ago

@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 commented 3 months ago

@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