将我自己的项目从早期(几个月前)版本的 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:无法将参数日志"绑定到 ILogger 类型.确保绑定支持参数类型.如果您使用绑定扩展(例如 ServiceBus、Timers 等),请确保您已在启动代码中调用了扩展的注册方法(例如 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)的最后一个日志记录参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!