繁体   English   中英

Azure Function v1.x 可以更新为使用 Microsoft.Azure.WebJobs 3.x 吗?

[英]Can Azure Function v1.x be updated to use Microsoft.Azure.WebJobs 3.x?

我正在努力将我们的 Azure Blob Storage (WindowsAzure.Storage) 包从折旧的 9.3.3 版本更新为 Microsoft.Azure.Storage.Blob 替代品。 这需要更新 Microsoft.Azure.WebJobs:v2.2.0 到 v3.0.x。 在完成 package 更新和 azure 功能的以下签名修订后; 由于 TraceWriter 导致以下错误(修订版 1),它将不再运行:

Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'traceLog' to type TraceWriter. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).

然后我尝试将其转换为 ILogger(修订版 2),并得到了类似的错误:

Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'traceLog' to type ILogger. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).

问题

可以为 Microsoft.Azure.WebJobs 从 v2.2.0 更新到 v3.0.x 的 Azure Functions v1.x 吗? 还是 Azure Functions v1.x 依赖于 Microsoft.Azure.WebJobs v2.2.x? 我缺少什么配置来连接日志?

环境

Azure Functions = 1.38 
Target Framework = .NET Framework 4.8

-原来的-

[FunctionName("PlaceOrder")]
public static void OrderImport([BlobTrigger("pending/{filename}", Connection = "storage")]Stream inputBlob, string filename, TraceWriter traceLog)

-修订版 1-

[FunctionName("PlaceOrder")]
public static void OrderImport([Blob("pending/{filename}", Connection = "storage")]Stream inputBlob, string filename, TraceWriter traceLog)

-修订版 2(使用 ILogger)-

[FunctionName("PlaceOrder")]
public static void OrderImport([Blob("pending/{filename}", Connection = "storage")]Stream inputBlob, string filename, ILogger traceLog)

您需要做的是将您的 Function 版本从 1.x 迁移到更高版本,并修改您的代码。

正如我们从文档中看到的, Function 1.x支持.NET Framework 4.7 ,而.NET Framework 4.8不受支持。

和,

虽然可以通过手动更新应用程序配置来进行“就地”升级,但从 1.x 升级到更高版本包括一些重大更改。 例如C#中,调试object由TraceWriter改为ILogger。

这是一个关于ILogger的简单示例,有关更多信息,您应该 go 到文档

public static class SimpleExample
{
    [FunctionName("QueueTrigger")]
    public static void Run(
        [QueueTrigger("myqueue-items")] string myQueueItem, 
        ILogger log)
    {
        log.LogInformation($"C# function processed: {myQueueItem}");
    }
}

提示:检查.csproj文件中的TargetFramework版本和AzureFunctionsVersion版本以及Microsoft.Net.Sdk.Functions NuGet版本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM