代码之家  ›  专栏  ›  技术社区  ›  Carlos Rodriguez

未在预编译Azure函数的参数中初始化ILogger实例

  •  2
  • Carlos Rodriguez  · 技术社区  · 9 年前

    我在Visual Studio 2017中用C语言编写了一个预编译的Azure函数项目,遵循所述步骤 here 或 here . 我想替换 TraceWriter 2.1.0-beta1 ILogger 允许直接绑定到Application Insights logger的绑定。我还添加了应用程序设置 APPINSIGHTS_INSTRUMENTATIONKEY 使用有效的Application Insights instrumentation密钥。更换后 跟踪写入程序 带有 ILogger 参数,我触发函数并得到以下错误响应:

    {
        "id": "497256d0-1c3a-4a10-a1cc-41b771305338",
        "requestId": "e546219e-7e38-4fa7-80cf-b06e0b8f4018",
        "statusCode": 500,
        "errorCode": 0,
        "messsage": "Exception while executing function: Functions.HelloHttpTrigger -> Exception binding parameter 'log' -> No value was provided for parameter 'log'.",
        "errorDetails": "Microsoft.Azure.WebJobs.Host.FunctionInvocationException : Exception while executing function: Functions.HelloHttpTrigger ---> System.InvalidOperationException : Exception binding parameter 'log' ---> System.InvalidOperationException : No value was provided for parameter 'log'.\r\n   at Microsoft.Azure.WebJobs.Host.Bindings.Invoke.ClassInvokeBinding`1.BindAsync(BindingContext context)\r\n   at async Microsoft.Azure.WebJobs.Host.Triggers.TriggeredFunctionBinding`1.BindCoreAsync[TTriggerValue](ValueBindingContext context,Object value,IDictionary`2 parameters) \r\n   End of inner exception\r\n   at Microsoft.Azure.WebJobs.Host.Executors.DelayedException.Throw()\r\n   at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithWatchersAsync(IFunctionInstance instance,IReadOnlyDictionary`2 parameters,TraceWriter traceWriter,CancellationTokenSource functionCancellationTokenSource)\r\n   at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(??)\r\n   at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(??) \r\n   End of inner exception\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(??)\r\n   at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.TryExecuteAsync(IFunctionInstance functionInstance,CancellationToken cancellationToken)\r\n   at Microsoft.Azure.WebJobs.Host.Executors.ExceptionDispatchInfoDelayedException.Throw()\r\n   at async Microsoft.Azure.WebJobs.JobHost.CallAsyncCore(MethodInfo method,IDictionary`2 arguments,CancellationToken cancellationToken)\r\n   at async Microsoft.Azure.WebJobs.Script.ScriptHost.CallAsync(String method,Dictionary`2 arguments,CancellationToken cancellationToken)\r\n   at async Microsoft.Azure.WebJobs.Script.WebHost.WebScriptHostManager.HandleRequestAsync(FunctionDescriptor function,HttpRequestMessage request,CancellationToken cancellationToken)\r\n   at async Microsoft.Azure.WebJobs.Script.WebHost.Controllers.FunctionsController.ExecuteAsync(HttpControllerContext controllerContext,CancellationToken cancellationToken)\r\n   at async System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)\r\n   at async System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)\r\n   at async Microsoft.Azure.WebJobs.Script.WebHost.Handlers.SystemTraceHandler.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)\r\n   at async Microsoft.Azure.WebJobs.Script.WebHost.Handlers.WebScriptHostHandler.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)\r\n   at async System.Web.Http.HttpServer.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)"
    }
    

    所以没有 伊洛格

    2 回复  |  直到 9 年前
        1
  •  2
  •   Carlos Rodriguez    9 年前

    正如米哈伊尔指出的答案所示,我不得不下载Nuget软件包 Microsoft.NET.Sdk.Functions v1.0.4。但是为了能够安装它,我必须安装2.1.0-beta4版本的软件包 Microsoft.Azure.WebJobs 和 Microsoft.Azure.WebJobs.Extensions ; 和版本1.0.0-beta4 Microsoft.Azure.Webjobs.Extensions.Http . 为了让这个项目得以实施,我不得不添加 <Target Name="RunResolvePublishAssemblies" /> 在项目文件中。

        2
  •  1
  •   Damian W    8 年前

    我刚刚遇到了一个问题,试图得到一个。net Core 2.1功能应用程序使用 Microsoft.NET.Sdk.Functions@1.0.14 在Azure上运行。

    我需要设置 FUNCTIONS_EXTENSION_VERSION 到 beta 在应用程序设置中。您可以在Azure门户中执行此操作。

    有人提到了这一点 https://stackoverflow.com/a/48461404/2896369 .

    推荐文章