2017-10-04 123 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" />