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

本秂侑毒 提交于 2019-12-07 01:31:03

问题


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: 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.).

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.

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)

I did not try to deploy this to Azure.

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.


回答1:


Microsoft.Extensions.Logging.Abstractions is the correct assembly.

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>


来源:https://stackoverflow.com/questions/46470549/last-logging-parameter-of-azure-function-ilogger-or-tracewriter-not-accepted

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!