2017-10-04 8 views
0

hereまたはhereの手順に従って、C#でVisual Studio 2017でプリコンパイルされたAzure関数プロジェクトを作成しました。 TraceWriterのログを、Microsoft.Extensions.Logging.ILoggerインターフェイスを通じてApplication Insightsのログに置き換えます。そのために、Microsoft.Azure.WebJobs Nugetパッケージを2.1.0-beta1にアップデートしました。これにはApplication Insightsロガーに直接バインドできるILoggerバインディングが含まれています。また、アプリケーション設定APPINSIGHTS_INSTRUMENTATIONKEYに有効なApplication Insights計測キーを追加しました。​​パラメータで私の機能の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.WebJobsとバージョンMicrosoft.Azure.WebJobs.Extensionsのバージョン2.1.0-beta4をインストールする必要がありました。 Microsoft.Azure.Webjobs.Extensions.Httpのバージョン1.0.0-beta4。また、プロジェクトを構築するために、<Target Name="RunResolvePublishAssemblies" />をプロジェクトファイルに追加する必要がありました。

関連する問題