Azure 函数无法绑定 ILogger [英] Azure Function fails to bind ILogger

查看:18
本文介绍了Azure 函数无法绑定 ILogger的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的函数引用了一个引用 Microsoft.Extensions.Logging.Abstractions 2.0.0 的程序集.如果我将对该版本的 nuget 引用添加到函数的程序集中,函数执行将失败并显示:

My function is referencing an assembly that references Microsoft.Extensions.Logging.Abstractions 2.0.0. If I add a nuget reference to that version to the function's assembly, function execution fails with:

[2018 年 1 月 25 日晚上 11:14:46] Microsoft.Azure.WebJobs.Host:索引错误方法TrainingFunction.Run".Microsoft.Azure.WebJobs.Host:不能将参数log"绑定到 ILogger.确保参数类型是绑定支持.如果您使用绑定扩展(例如ServiceBus、Timers 等)确保你已经调用了注册启动代码中扩展的方法(例如config.UseServiceBus()、config.UseTimers() 等).

[1/25/2018 11:14:46 PM] Microsoft.Azure.WebJobs.Host: Error indexing method 'TrainingFunction.Run'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'log' 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 函数中使用较新的记录器?(SDK 1.0.7)

Is it possible to use the newer logger in Azure functions ? (SDK 1.0.7)

推荐答案

可能发生的情况是 SDK 绑定到 ILogger 程序集的版本 X,而您的用户代码绑定到版本 Y.然后绑定引擎不会t 将您的参数类型识别为相同,因为它们来自不同的程序集.(这也可能发生在任何其他类型上).

What is probably happening is that the SDK is binding to version X of the ILogger assembly and your user code is binding to version Y. The binding engine then doesn't recognize your parameter's type as being the same since they're from different assemblies. (this can happen with any other type too).

通常解决方法是:

  1. 查看 SDK 使用的块参考
  2. 使用那些现有的引用,不要添加具有不同版本的相同 dll.

这篇关于Azure 函数无法绑定 ILogger的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆