Comments (24)
By apologies for the delay - I moved jobs this week and have been settling in at the new place. I've emailed you the code we are using - hope it helps!
from functionmonkey.
Great thanks - leave it with me. It should work and I need to figure out why its not.
Best I can tell you've done nothing wrong.
from functionmonkey.
Thank you @adam-short for your extra detail to this. I haven't been able to respond until now but experienced the same issues you have adequately described you are having.
from functionmonkey.
I'm not going to have a lot of time over the next week - but I'll work something up as soon as I can and include it in the docs.
Thanks for reporting - bit of an oversight on my part for a common requirement.
from functionmonkey.
I've added a section to the docs:
https://functionmonkey.azurefromthetrenches.com/guides/crosscutting/logging.html
from functionmonkey.
When running locally and following your example docs, I get no build errors and func start
works fine. However, whenever a function goes to run I am greeted with the following;
System.Private.CoreLib: Exception while executing function: SbqFnFormatMetadata. AzureFromTheTrenches.Commanding: Error occurred during command execution. Microsoft.Extensions.DependencyInjection: Unable to resolve service for type 'Microsoft.Extensions.Logging.ILogger' while attempting to activate 'ICE.Handlers.FormatMetadataCommandHandler'.
I also get related errors for my other services that I have refactored to depend on ILogger that `AddLogging()1 should be providing;
System.Private.CoreLib: Exception while executing function: SbsFnBasicTaggingImages. AzureFromTheTrenches.Commanding: Error occurred during command execution. Microsoft.Extensions.DependencyInjection: No constructor for type 'ICE.Services.Implementations.AzureComputerVisionService' can be instantiated using services from the service container and default values.
My approach to using ILogger was to include it in the constructor of my command handlers, like such;
private readonly ILogger _log;
private readonly ICollaboroApiService _collaboroApi;
public FormatMetadataCommandHandler(
ILogger logging,
ICollaboroApiService collaboroApiService
)
{
_collaboroApi = collaboroApiService;
_log = logging;
}
The documentation doesn't show you how this ILogger is utilised, so I assumed this was a logical choice.
Is there any obvious reason for this to be happening? I am running locally on the latest version of FM.
I have attempted to find some docs on whether there are particular steps to be taken to use ILogger locally, but can't find anything specific to this use case.
from functionmonkey.
Hmmm. That should be ok. You're right - there should be no specific steps to take.
Can you share with me the Setup block from your function app configuration?
from functionmonkey.
Yeah sure! Here it is:
builder
.Setup((serviceCollection, commandRegistry) =>
{
/*
* Service Injections
*/
serviceCollection
.AddTransient<IAzureServiceBusService, AzureServiceBusService>()
.AddTransient<ICollaboroApiService, CollaboroApiService>()
.AddTransient<ITableService<Metadata>, TableService<Metadata>>()
.AddTransient<IGoogleVisionService, GoogleVisionService>()
.AddTransient<IAzureComputerVisionService, AzureComputerVisionService>()
.AddLogging();
/*
* Integration Handlers
*/
commandRegistry.Register<RequestHandler>();
commandRegistry.Register<FormatMetadataCommandHandler>();
/*
* Metadata Handlers
*/
commandRegistry.Register<BasicTaggingImagesHandler>();
commandRegistry.Register<FaceRecognitionImagesHandler>();
commandRegistry.Register<OcrImagesHandler>();
})
from functionmonkey.
Thanks. That all looks ok. And if you take the dependency on ILogger out it works?
I'm working on a project that uses ILogger with FunctionMonkey at the moment so I'll do some digging around.
from functionmonkey.
I will check for you now - give me a quick moment as I have like 9 services that depend on it ahaha
from functionmonkey.
Yep, it does work - I injected a dummy class implementing ILogger in the same location as AddLogger
and it worked totally fine
from functionmonkey.
This is working for me. Really strange.
Is your project open source? Or if its closed source would you mind if I took a look at it?
from functionmonkey.
It's closed source but I see no issues with you having a look. How do you want me to get it to you? I could send you a zip file
from functionmonkey.
If you don't mind that would be great - I'd love to get to the bottom of it. My email address is james at accidentalfish dot com.
from functionmonkey.
Wait - actually, the email is bouncing, I think the given address may be wrong?
from functionmonkey.
No worries - I'm running round like crazy myself at the moment. Hope you're enjoying the new job!
Weird. That's the right email address.
You could also try:
james at microserviceanalytics dot com
from functionmonkey.
Hey James I haven't gotten around to it as I figured out how to implement it via AI in the way i wanted to - only downside is the manual flushing. And my boss has now asked not to share the code with anyone : (
Have you had any progress on the bug?
from functionmonkey.
No worries.
I haven't been able to reproduce it I'm afraid but based on some issues in the main Azure Functions repo I've a couple more ideas.
from functionmonkey.
I was also having some issues around ILogger. I do have some extra information.
I noticed that just adding serviceCollection.AddLogging()
or even any configuration to the overloaded logBuilder, allows me to resolve ILogger<T>
but not just ILogger
. Additionally, it seemed to fail in the .Run(...,ILogger log) (from the template), so it never got down to the command.
I had created a Startup class that I ended up not using, so my short term solution was to:
services.AddLogging();
services.AddTransient<ILogger>(sp => sp.GetRequiredService<ILogger<Startup>>());
And now everything works. After digging into the AddLogging
extension, its not registering ILogger
, but ILoggerFactory
and ILogger<>
(and all the Options plumbing so it can register LoggerFilterOptions
). I had ILogger<T>
on my handler, but it turns out I had just ILogger
in the constructor for my ITokenValidator
and thats what was blowing up. Don't know what, or if, you want to do about that. I suppose you could add a singleton to the container with the ILogger
passed into the function. Or just change your examples to use ILogger<T>
from functionmonkey.
Thanks for all of the above - I've been taking a look myself (apologies for the delay - super busy with client work) and wiring things up to App Insights. Just hoping from a pointer from the Functions team as to which way they're going with the logger support in the future then I'll make an update.
from functionmonkey.
@JamesRandall I have also sent you an email with a suggestion, I know you are quite busy. My suggestion is to pass the instance of the ILogger from the function into the context so that we can use the one that was created from Azure's side.
from functionmonkey.
Thanks, thats one of the options I’ve looked at but I dislike that it’s not directly injectable. Another is to use an implementation factory on the service collection coupled to an asynclocal set by the template. And a final approach I’m looking at is to get the full AddLogging stuff working but linked back to the function supplied logger - I’ve only partially explored this as I wanted to use ILogger with app insights and that required getting all that going. What I’ve not tried, but what I suspect, is that if I link that back to the function logger is that I’ll get double logging going on.
Thanks for your patience, much appreciated!
from functionmonkey.
Startup
@abezverkov
can you tell me what is in your startup class? I am having the same issues
from functionmonkey.
v0.20.0 should now resolve this.
The ILogger that Azure Functions passes to the function entry point is available for injection to handlers and their dependencies. If you have any code that is registering loggers directly against the IServiceCollection this will need to be removed or it will overwrite this (which you may choose to do but will need to wire up to your outputs yourselves).
from functionmonkey.
Related Issues (20)
- CamelCaseJsonSerializer does not work for ExpandoObject
- HttpResponseHandler not used for BadParameterResponse in http.csharp.handlebars HOT 1
- Receive and add CancellationToken to DI to enable for graceful shutdowns HOT 1
- Compiling Azure Functions with NuGet package dependencies fails HOT 13
- Problems with StorageQueue in 4.0.56-beta4 HOT 2
- Event Grid Triggers
- Unable to upload a file
- HowTo BeforeServiceProviderBuild HOT 1
- Solution Structure
- Http Trigger: AuthorizationLevel.Anonymous runs ClaimsPrincipalAuthorization but it should be ignored HOT 3
- How to access Cookie (and QueryString) collection ?
- Future of Function Monkey HOT 10
- Compiler Build Error with Entity Framework Core HOT 4
- Add Validators via Assembly search not working HOT 2
- Primitives / Arrays in HTTP body
- Need a way to access full HttpContext HOT 2
- FunctionMonkey.Compiler can't be built
- Accessing request headers
- Azure App Configuration in Configuration.
- CosmosDB lease container appears inoperable
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from functionmonkey.