I'm using an Azure Durable Function<\/a> to orchestrate other functions, currently contained in the same project. I want to configure services and logging for those orchestrated functions. How can I do that?
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureLogging(loggingBuilder => { loggingBuilder.SetMinimumLevel(LogLevel.Trace); })... etc. pp.
By default the ILogger instance is injected in your functions, unless you are using DI.All you need to do is Use the ILogger.
[FunctionName("funcname")]
public async static Task RunOrchestrator(
[OrchestrationTrigger] DurableOrchestrationContext context,
ILogger log)
{
log.LogInformation("Starting Orchestration");
}
Check Incase if you using Dependency injection you should just do the below in your startup builder.Services.AddLogging();
So the solution is to use a FunctionsStartup<\/code> class as outlined here<\/a> .
This should make dependency injection work, also for Durable Functions.
What I tried is adding an additional parameter (
myService<\/code> ) to the static methods like so:
[FunctionName("DurableFunctionsOrchestrationCSharp1_Hello")]
public static string SayHello([ActivityTrigger] string name, ILogger log, IMyService myService)
{
log.LogInformation($"Saying hello to {name}.");
return $"Hello {name}!";
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.