rebus-org / Rebus.Microsoft.Extensions.Logging

:bus: Microsoft Logging Extensions integration for Rebus
https://mookid.dk/category/rebus
Other
3 stars 7 forks source link

Add resolver function support to allow resolving from an IoC container #4

Closed jorenp closed 4 years ago

jorenp commented 4 years ago

I was looking at integrating Rebus with App Insights. But I'm struggling a bit with the ILoggerFactory reference. We don't add the LoggerFactory directly to the container at the moment. So we don't have a reference when configuring the container. Adding support for passing in a resolver function would allow us to use the DI container. image

Or is this a daft idea and should I just manually create a LoggerFactory instance?

mookid8000 commented 4 years ago

When you're using MIcrosoft DI, you can AddRebus with the overload that passes IServiceProvider in, and then you should be able to do something like this:

services.AddRebus((configure, provider) =>
    configure.Transport(...)
        .Logging(l => l.MicrosoftExtensionsLogging(provider.GetRequiredService<ILoggerFactory>()))
        .(...)
);

Isn't this what you need?

jorenp commented 4 years ago

Completely missed that overload, sorry. That solves it indeed. Thanks, I'll close this issue.

mookid8000 commented 4 years ago

Perfect! 🙂