-
Notifications
You must be signed in to change notification settings - Fork 42
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
Inject ILogger in a service. #10
Comments
Please yes. |
+1 Does it work if we accept an ILoggerFactory in the constructors instead? |
It looks like it will pass in an However in order to get the created logger to output to the functions host I had to adjust the category name to look like I'm guessing that the reason an ILogger is passed along today is because it retains the category name of the Function and the console / function host will only output logs for that function from the associated category... Which makes it a challenge if you are injecting a singleton service in multiple functions that you all want to have logs output from. |
Ok I found It would be nice to register one of these up front in Startup.cs so |
More info in comments in the code on LogCategories here: |
I think Host.Singleton is more to do with the singleton attribute which appears to be related to durable functions. https://docs.microsoft.com/en-us/azure/app-service/webjobs-sdk-how-to#singleton-attribute. For now I've decided switched to this below, with a category that I create based on function name when I'm in the scope of a function itself (to be in line with the Prior to official release of this DI extension when I had made my own DI extension binding based on various write-ups in the community, I was intercepting the service collection in the |
Use
Some updated comments/links with more details here: Azure/azure-functions-host#2720 (comment) |
Closing this as the comment above addresses the issue. |
Thank you for the guidance @brettsam! |
Is it somehow possible to inject the
ILogger
into the constructor of a Service? I rather not pass on the instance, especially not when I have a multi layer (service / repository) pattern.The text was updated successfully, but these errors were encountered: