nblumhardt / serilog-timings

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

[Readme] Levelling a contextual ILogger? #45

Closed InsanePup closed 2 years ago

InsanePup commented 2 years ago

First, thanks to all contributors for a really useful library.

Is it possible to level a contextual logger? If it is, can we have an example please? If it is not, can you please call that out?

nblumhardt commented 2 years ago

Hi! You need using SerilogTimings.Extensions, this will light up logger.OperationAt(...).

HTH, Nick

InsanePup commented 2 years ago

When I talk about a contextual logger I mean ILogger<MyType> which is in the Microsoft namespace. It doesn't appear that I can specify a logging level when using one of these.

nblumhardt commented 2 years ago

This repo is for extending Serilog/Serilog's ILogger. The Microsoft ILogger is a different thing, but you might find a "timings" library out there for it (or be able to fork/adapt this one).

InsanePup commented 2 years ago

Sorry, GitHub ate my angle brackets (corrected now). I'm talking about the Microsoft typed Logger interface when configured to use the Serilog implementation. It appears that I can't use the typed interface if I want to use this library. I haven't used Serilog before so maybe people generally don't use it this way?

nblumhardt commented 2 years ago

Thanks for the reply! I understood what you meant by ILogger :+1:

This project is for people who are using Serilog directly, and it extends Serilog's API.

You can also choose to use MEL, and route messages from its ILogger<T> through Serilog, but then you're not using Serilog's API at all, and this library doesn't target that scenario.

A "MEL Timings" that shipped extension methods for MEL's ILogger<T> would be cool to see - it'd be a separate project, though.

Hope this helps!

natehaby commented 2 years ago

I've been using it with ILogger for about 2+ years. It works well. It takes about an hour to rip out the Serilog specific stuff. I have not included a link on here only because it was quick and dirty, no tests, etc. I do not use it in anything mission critical at this time. Doing a proper fork has been on my list, I just haven't gotten around to it.