c# - 如何从事件函数获取 ILogger?

标签 c# azure azure-functions azure-durable-functions

我正在未来项目的原型(prototype)中使用 Durable Azure Function。

基本上,我有一个由启动 Orchestrator 的 HTTP POST 请求触发的客户端 Azure 函数。然后,Orchestrator 决定触发一个 Activity。没什么复杂的。

这是我正在做的事情的示例:

[FunctionName("ClientFunction")]
public static async Task<HttpResponseMessage> OnHttpTriggerAsync([HttpTrigger(AuthorizationLevel.Anonymous, "post")]
            HttpRequestMessage request, [OrchestrationClient] DurableOrchestrationClient starter, ILogger logger)
{
    // Triggers the orchestrator.
    string instanceId = await starter.StartNewAsync("OrchestratorFunction", null);

    return new HttpResponseMessage(HttpStatusCode.OK);
}


[FunctionName("OrchestratorFunction")]
public static async Task DoOrchestrationThingsAsync([OrchestrationTrigger] DurableOrchestrationContext context, ILogger logger)
{
    // Triggers some serious activity.
    await context.CallActivityAsync("ActivityFunction", null);
}

[FunctionName("ActivityFunction")]
public static Task DoAnAwesomeActivity([ActivityTrigger] DurableActivityContext context)
{
    // Short & Sweet activity...
    // Wait... Where's my logger?
}

Orchestrator 和客户端函数都被赋予了一个 ILogger,但事件函数没有;如stateddocumentation (无论是特定参数还是 DurableActivityContext 实例),Activity 函数仅获取一个参数。而且我并不认为声明这些方法的静态类可以保留对该 ILogger 的引用。

我知道事件函数应该执行一项小工作,但如果我能够记录在出现问题时使用适当的值调用事件(并且它会:)),我会更舒服。

问题

Activity 如何访问 ILogger

最佳答案

It is not possible to pass multiple parameters to an activity function directly. The recommendation in this case is to pass in an array of objects or to use ValueTuples objects in .NET.

这个restriction您关心的是我们从 Orchestrator 传递到 Activity Function 的参数。这并不意味着我们只能在 Activity 方法签名中使用一个参数。请随意添加 ILogger 并根据需要完成您的工作。

关于c# - 如何从事件函数获取 ILogger?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54598479/

相关文章:

azure - 在 Web 应用程序中安装 Azure 文件共享时,我收到 InvalidCredentials 状态

azure - 如何在Azure函数应用程序中配置CORS?

c# - 使用 asp.net 反转 tsv/csv 文件或仅读取最后一行

Azure 容器实例未连接 kafka 集群

python - 使用适用于 Python 的 Azure 存储 SDK 将多个文件从文件夹上传到 Azure Blob 存储

Azure 逻辑应用程序和函数应用程序性能差异

c# - 从 Azure Function 中读取日志

c# - 如何在设计时将图像设置为窗口窗体中的超链接

c# - 如何在生成时删除 XML 中的类型?

c# - 如何在 Parallel.For 中配置最大线程数