2017-10-04 27 views
0

我已经写了预编译Azure的功能在Visual Studio 2017年在C#以下步骤项目描述herehere的参数未初始化。我想申请洞察通过Microsoft.Extensions.Logging.ILogger界面登录,以取代TraceWriter记录。对于我更新了Microsoft.Azure.WebJobs NuGet包到2.1.0-beta1版本,其包括ILogger结合,使直接结合到应用程序数据分析记录器。我还添加了应用程序设置APPINSIGHTS_INSTRUMENTATIONKEY和一个有效的应用程序见解工具密钥。与​​参数代替我的函数的参数TraceWriter后,我触发功能,并收到以下错误响应:ILogger例如在预编译Azure的功能

{ 
    "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)" 
} 

所以不能创建的​​实例。但是,如果我使用函数脚本创建项目而不是预编译函数,那么ILogger实例将正确实例化。这是否意味着ILogger的实例化只适用于函数脚本?我希望情况并非如此,那么我应该如何增加预编译函数的设置才能使其工作?

+0

你见过https://stackoverflow.com/a/46471220/1171619? – Mikhail

回答

0

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