Martin
Martin

Reputation: 398

Using ILogger in Azure durable function activity?

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!

Upvotes: 1

Views: 5853

Answers (1)

HariHaran
HariHaran

Reputation: 4119

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

Upvotes: 6

Related Questions