ILogger instance not initialized in parameter of precompiled Azure function

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



ILogger instance not initialized in parameter of precompiled Azure function



I have written a precompiled Azure Function project in Visual Studio 2017 in C# following the steps described here or here. I want to replace TraceWriter logging with Application Insights logging through the Microsoft.Extensions.Logging.ILogger interface. For that I updated the Microsoft.Azure.WebJobs Nuget package to version 2.1.0-beta1, which includes the ILogger binding that enables binding directly to the Application Insights logger. I have also added the app setting APPINSIGHTS_INSTRUMENTATIONKEY with a valid Application Insights instrumentation key. After replacing the TraceWriter parameter of my function with an ILogger parameter, I trigger the function and get the following error response:


TraceWriter


APPINSIGHTS_INSTRUMENTATIONKEY


TraceWriter


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'.rn at Microsoft.Azure.WebJobs.Host.Bindings.Invoke.ClassInvokeBinding`1.BindAsync(BindingContext context)rn at async Microsoft.Azure.WebJobs.Host.Triggers.TriggeredFunctionBinding`1.BindCoreAsync[TTriggerValue](ValueBindingContext context,Object value,IDictionary`2 parameters) rn End of inner exceptionrn at Microsoft.Azure.WebJobs.Host.Executors.DelayedException.Throw()rn at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithWatchersAsync(IFunctionInstance instance,IReadOnlyDictionary`2 parameters,TraceWriter traceWriter,CancellationTokenSource functionCancellationTokenSource)rn at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(??)rn at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(??) rn End of inner exceptionrn at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()rn at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(??)rn at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.TryExecuteAsync(IFunctionInstance functionInstance,CancellationToken cancellationToken)rn at Microsoft.Azure.WebJobs.Host.Executors.ExceptionDispatchInfoDelayedException.Throw()rn at async Microsoft.Azure.WebJobs.JobHost.CallAsyncCore(MethodInfo method,IDictionary`2 arguments,CancellationToken cancellationToken)rn at async Microsoft.Azure.WebJobs.Script.ScriptHost.CallAsync(String method,Dictionary`2 arguments,CancellationToken cancellationToken)rn at async Microsoft.Azure.WebJobs.Script.WebHost.WebScriptHostManager.HandleRequestAsync(FunctionDescriptor function,HttpRequestMessage request,CancellationToken cancellationToken)rn at async Microsoft.Azure.WebJobs.Script.WebHost.Controllers.FunctionsController.ExecuteAsync(HttpControllerContext controllerContext,CancellationToken cancellationToken)rn at async System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)rn at async System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)rn at async Microsoft.Azure.WebJobs.Script.WebHost.Handlers.SystemTraceHandler.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)rn at async Microsoft.Azure.WebJobs.Script.WebHost.Handlers.WebScriptHostHandler.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)rn at async System.Web.Http.HttpServer.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)"



So no instance of ILogger can be created. However, if I create a project with a function script, instead of a precompiled function, then the ILogger instance is correctly instantiated. Does this mean that the instantiation of ILogger only works with function scripts?? I hope that's not the case, so what should I add to the setup of my precompled function to make it work?


ILogger





Have you seen stackoverflow.com/a/46471220/1171619 ?
– Mikhail
Oct 4 '17 at 20:11




2 Answers
2



As indicated in the answer pointed by Mikhail I had to download the Nuget package Microsoft.NET.Sdk.Functions v1.0.4. But to be able to install it I had to install version 2.1.0-beta4 of packages Microsoft.Azure.WebJobs and Microsoft.Azure.WebJobs.Extensions; and version 1.0.0-beta4 of Microsoft.Azure.Webjobs.Extensions.Http. And to get the project to build I had to add <Target Name="RunResolvePublishAssemblies" /> in the project file.


Microsoft.NET.Sdk.Functions


Microsoft.Azure.WebJobs


Microsoft.Azure.WebJobs.Extensions


Microsoft.Azure.Webjobs.Extensions.Http


<Target Name="RunResolvePublishAssemblies" />



I just had this issue trying to get a .net Core 2.1 function app using Microsoft.NET.Sdk.Functions@1.0.14 running on Azure.


Microsoft.NET.Sdk.Functions@1.0.14



I needed to set FUNCTIONS_EXTENSION_VERSION to beta in the Application settings. You can do this in the Azure Portal.


FUNCTIONS_EXTENSION_VERSION


beta



This was mentioned https://stackoverflow.com/a/48461404/2896369.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard