KuraiAndras / Extenject.Microsoft

MIT License
9 stars 2 forks source link

AddLogging Extension method not compatible #16

Open Rokerekor opened 1 year ago

Rokerekor commented 1 year ago

public static IServiceCollection AddLogging(this IServiceCollection services, Action<ILoggingBuilder> configure); in the Microsoft.Extensions.Logging assembly will not work as expected. The translator will detect multiple ILoggingProviders and throw an exception. If only one is provided, it will not be injected properly and [Inject] will provide a Logger implementation that appears to do nothing.

I got around this by manually doing what the extension method does,

ILoggerFactory loggerFactory = LoggerFactory.Create(b => ...); services.AddSingleton(loggerFactory) services.TryAdd(ServiceDescriptor.Singleton(typeof(ILogger<>), typeof(Logger<>)));

Sorry if this is a terribly uninformed post. It took me a while to get logging working and I'm hoping this will be useful information to someone at some point.

Thanks for making this Kurai.

KuraiAndras commented 1 year ago

Yeah, so right now the library does not conform to Microsoft's DI specification, this issue tracks it: https://github.com/KuraiAndras/Extenject.Microsoft/issues/11. Right now I have set up the test suite so it will be clear when every operation conforms to the expected behavior.

To be honest I have created this project as proof of concept, but as of now I do not want to actively develop it. I am glad to merge PRs if they improve adherence to the specification, but I don't want to work on this actively.

Regarding your issue: to me it seems that right now you are stuck with your manual registration and I am glad that it works for you. You could either fix the issue presenting when calling the AddLogging method, or as a rather wild alternative I would suggest you try my other project Injecter, which can be used in a somewhat similar way as extenject. Here is the documentation.