【问题标题】:Can Azure Function v1.x be updated to use Microsoft.Azure.WebJobs 3.x?能否更新 Azure Function v1.x 以使用 Microsoft.Azure.WebJobs 3.x?
【发布时间】:2020-12-29 20:31:41
【问题描述】:

我正在努力将我们的 Azure Blob 存储 (WindowsAzure.Storage) 包从折旧的 9.3.3 版本更新为 Microsoft.Azure.Storage.Blob 替代品。这需要更新 Microsoft.Azure.WebJobs:v2.2.0 到 v3.0.x。在完成包更新和对 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.).

问题

Azure Functions v1.x 能否针对 Microsoft.Azure.WebJobs 从 v2.2.0 更新到 v3.0.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)

【问题讨论】:

标签: c# azure-functions


【解决方案1】:

你需要做的是migrating your Function version from 1.x to later,然后修改你的代码。

docs可以看出,Function 1.x支持.NET Framework 4.7,而不支持.NET Framework 4.8

还有,

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

这里是一个关于ILogger的简单例子,更多信息你应该去docs

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 版本。

【讨论】:

  • 1) 感谢您提供的链接。从 1.x 升级到更高版本还需要升级到 .NET Core(并使用相应的库(如 Authorization 和 Entity Framework)重写大部分应用程序)。这远远超出了这项工作的范围。 2)我很欣赏文档的链接。我们在 4.8 上成功运行,并且运行良好。文档已过时。问题:Azure Function v1.x / .NET Framework 4.8 约束(不需要 .Net Core 升级)内是否有 WebJobs / 未折旧 Azure Blob 存储库的更新路径?
  • 对于此要求,您可以在 azure 门户上提出支持票。您可以按照此页面上的步骤创建票证:docs.microsoft.com/en-us/azure/azure-portal/supportability/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多