2017-10-04 3 views
0

here 또는 here에 설명 된 단계에 따라 Visual Studio 2017에서 C#으로 미리 컴파일 된 Azure 함수 프로젝트를 작성했습니다. TraceWriter 로깅을 Microsoft.Extensions.Logging.ILogger 인터페이스를 통해 Application Insights 로깅으로 바꾸고 싶습니다. 이를 위해 Microsoft.Azure.WebJobs Nuget 패키지를 2.1.0-beta1 버전으로 업데이트했습니다. 여기에는 Application Insights logger에 직접 바인딩 할 수있는 ILogger 바인딩이 포함되어 있습니다. 또한 유효한 Application Insights 계측 키를 사용하여 응용 프로그램 설정 APPINSIGHTS_INSTRUMENTATIONKEY을 추가했습니다. ILogger 매개 변수를 내 함수의 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 인스턴스가 올바르게 인스턴스화됩니다. 이것은 ILogger의 인스턴스 생성이 함수 스크립트에서만 작동한다는 것을 의미합니까 ?? 그런 경우가 아니기를 바랍니다. 미리 컴파일 된 함수를 설정하면 어떻게 작동합니까?

+0

https://stackoverflow.com/a/46471220/1171619를 보셨습니까? – Mikhail

답변

0

Mikhail이 지적한 답변에서 알 수 있듯이 Nuget 패키지 Microsoft.NET.Sdk.Functions v1.0.4를 다운로드해야했습니다. 그러나 그것을 설치할 수 있으려면 패키지 Microsoft.Azure.WebJobsMicrosoft.Azure.WebJobs.Extensions의 버전 2.1.0-beta4를 설치해야했습니다. Microsoft.Azure.Webjobs.Extensions.Http의 1.0.0-beta4 버전 그리고 프로젝트를 만들려면 <Target Name="RunResolvePublishAssemblies" />을 프로젝트 파일에 추가해야했습니다.

관련 문제