加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 不接受Azure功能(ILogger或TraceWriter)的上次日志记录参

发布时间:2020-12-15 07:47:09 所属栏目:百科 来源:网络整理
导读:将我自己的项目从早期(几个月前)版本的Azure Functions升级到当前版本后,从VS启动时出现以下错误. GetLoginUrl: Microsoft.Azure.WebJobs.Host: Error indexing method ‘Login.GetLoginUrl’. Microsoft.Azure.WebJobs.Host: Cannot bind parameter ‘log’
将我自己的项目从早期(几个月前)版本的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日志作为我方法的最后一个参数,但后来我发现我应该使用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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读