不接受 Azure 函数(ILogger 或 TraceWriter)的最后一个日志记录参数

Last logging parameter of Azure Function (ILogger or TraceWriter) not accepted

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

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 来代替。在我进行更改之前,我遇到了与上述相同的错误。

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

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

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

不幸的是,创建一个全新的 Functions 项目没有帮助,因为没有 .CS 文件可供查找以更正此问题。

Microsoft.Extensions.Logging.Abstractions 是正确的装配。

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

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