不接受Azure函数的最后一个日志记录参数(ILogger或TraceWriter) [英] Last logging parameter of Azure Function (ILogger or TraceWriter) not accepted

查看:120
本文介绍了不接受Azure函数的最后一个日志记录参数(ILogger或TraceWriter)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将我自己的项目从早期(几个月前)的Azure Functions版本升级到当前版本后,从VS启动时出现以下错误.

After upgrading my own project from an earlier (a few months back) version of Azure Functions to current, I get the following error upon launching from VS.

GetLoginUrl:Microsoft.Azure.WebJobs.Host:错误索引方法"Login.GetLoginUrl". Microsoft.Azure.WebJobs.Host:无法将参数"log"绑定到ILogger类型.确保绑定支持参数类型".如果使用绑定扩展(例如ServiceBus,Timer等),请确保已在启动代码中调用了扩展的注册方法(例如config.UseServiceBus(),config.UseTimers()等). ).

GetLoginUrl: Microsoft.Azure.WebJobs.Host: Error indexing method 'Login.GetLoginUrl'. 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.).

之前,我曾经以TraceWriter log作为方法的最后一个参数,但是后来我发现我应该改用ILogger.在进行更改之前,我遇到了与上述相同的错误.

Before, I used to have TraceWriter log as the last parameter to my methods but then I found out I should be using ILogger instead. Before I made the change, I was getting the same error as above.

ILogger似乎已映射到程序集Microsoft.Extensions.Logging.Abstractions.也许这就是为什么它不被认可?应该使用哪个ILogger?这是方法签名.

The ILogger seems to be mapped to assembly Microsoft.Extensions.Logging.Abstractions. Perhaps this is why it is not recognized? Which ILogger should be used? Here is the method signature.

[FunctionName("GetLoginUrl")]
public static HttpResponseMessage GetLoginUrl(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)]HttpRequestMessage req,
    ILogger log)

我没有尝试将其部署到Azure.

I did not try to deploy this to Azure.

不幸的是,创建一个新的Functions项目无济于事,因为没有.CS文件可以查找来纠正此问题.

Unfortunately, creating a brand new Functions project does not help as there are no .CS files to look up to in order to correct this.

推荐答案

Microsoft.Extensions.Logging.Abstractions是正确的程序集.

您可能直接引用了一些较旧的NuGet软件包(例如Microsoft.Azure.WebJobs).如果是这样,请确保将其删除.除非您使用其他绑定,否则您的csproj引用应该看起来像这样简单:

You are probably referencing some older NuGet packages directly (e.g. Microsoft.Azure.WebJobs). If so, be sure to remove it. Unless you are using some additional binding, your csproj references should look as simple as this:

<ItemGroup>           
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.4" />
</ItemGroup>

这篇关于不接受Azure函数的最后一个日志记录参数(ILogger或TraceWriter)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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