1

I am using the azure functions for a table insert event trigger, specifically the durable functions, and I'm trying to to produce some logs in my activity function.

The problem is that the activity function does not receive any "ILogger", nor does the orchestrator, thus I don't have any access and cannot produce logs for debug.

The overall flow is:

HTTP request => Duarble HTTP starter => Durable functions orchestrator => Durable function activity.

Is there a way to create a logger instance for some class deriving from ILogger? Or perhaps a way to pass the ILogger instance from the HTTP starter down to the activity function?

Any solution would be much appreciated!

1 Answer 1

6

By default the ILogger instance is injected in your functions, unless you are using DI.

All you need to do is Use the ILogger which is injected into your functions. Example:

[FunctionName("Demo")]
public async static Task RunOrchestrator(
    [OrchestrationTrigger] DurableOrchestrationContext context,
    ILogger log)
{
    log.LogInformation("Starting Orchestration function");
}

Incase if you using Dependency injection you should just do the below in your startup builder.Services.AddLogging();

More Information :

https://github.com/Azure/azure-functions-host/issues/4858

https://github.com/Azure/azure-functions-host/issues/2720#issuecomment-503627355

Microsoft Docs

Sign up to request clarification or add additional context in comments.

7 Comments

By default the ILogger isn't injected in the Durable activity function. (It is howerver in the orchestration), so where should the "builder.Services.AddLogging()" be added?
Inorder to use builder.Services.AddLogging() you will need to add Statup class and make the function as dependency injected one
@HariHaran I've implemented DI for durable functions as well but the line above does not seem to work. Can't inject an ILogger via the function or the constructor? Any ideas?
@BillyRayValentine please raise a question with more error info,i'll check it out.
Hi @HariHaran, please see question here: stackoverflow.com/questions/58752340/…
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.