簡體   English   中英

"Azure Durable Functions - HostBuilder 等效項在哪里?"

[英]Azure Durable Functions - where's the HostBuilder equivalent?

我正在使用Azure 持久函數<\/a>來編排當前包含在同一項目中的其他函數。 我想為那些編排的功能配置服務和日志記錄。 我怎樣才能做到這一點?

這里有一些更詳細的信息:

在“普通”Azure 函數中,我有一個Program.cs<\/code>和一個Main<\/code>方法,其中包含以下代碼,用於設置函數執行的環境:

var host = new HostBuilder()
    .ConfigureFunctionsWorkerDefaults()
    .ConfigureLogging(loggingBuilder => { loggingBuilder.SetMinimumLevel(LogLevel.Trace); })... etc. pp.

默認情況下,ILogger 實例被注入到您的函數中,除非您使用 DI。您需要做的就是使用 ILogger。

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

如果您使用依賴注入, 請檢查Incase,您應該在啟動 builder.Services.AddLogging(); 中執行以下操作;

還要檢查

因此,解決方案是使用此處<\/a>概述的FunctionsStartup<\/code>類。 這應該使依賴注入工作,也適用於持久功能。

對我來說,它並沒有立即起作用,而且花了一段時間才弄清楚原因。 我嘗試的是向靜態方法添加一個附加參數( myService<\/code> ),如下所示:

[FunctionName("DurableFunctionsOrchestrationCSharp1_Hello")]
public static string SayHello([ActivityTrigger] string name, ILogger log, IMyService myService)
{
    log.LogInformation($"Saying hello to {name}.");
    return $"Hello {name}!";
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM