私が知る限り、現時点では、ローカルのazure関数プロジェクトにApplication Insightsを直接追加することはできませんでした。
これは回避策です:
自分で実装する必要があります。 NugetパッケージマネージャーからMicrosoft.ApplicationInsightsをインストールした後。
次に、TelemetryClientを使用して、紺碧にログを送信します。
詳細、あなたはコード以下を参照できます。
[FunctionName("HttpTriggerCSharp")]
public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage req, TraceWriter log)
{
var appInsights = GetTelemetryClient();
//track an event
appInsights.TrackEvent("I am starting now. I'm timer triggered");
// track a numeric value
appInsights.TrackMetric("Ticks based on current time", DateTime.Now.Ticks);
// track an exception
appInsights.TrackException(new Exception($"Random exception at {DateTime.Now}"));
// send data to azure
appInsights.Flush();
log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
log.Info("C# HTTP trigger function processed a request.");
// parse query parameter
string name = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
.Value;
// Get request body
dynamic data = await req.Content.ReadAsAsync<object>();
// Set name to query string or body data
name = name ?? data?.name;
return name == null
? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body")
: req.CreateResponse(HttpStatusCode.OK, "Hello " + name);
}
private static TelemetryClient GetTelemetryClient()
{
var telemetryClient = new TelemetryClient();
telemetryClient.InstrumentationKey = "Your InstrumentationKey";
return telemetryClient;
}
}
}
結果:Azureの機能へのアプリケーションの洞察(AI)テレメトリを追加
私が知っている限り、Application Insightsに情報を記録する必要がある場合。 Microsoft.ApplicationInsightsパッケージの使用を検討し、InstrumentationKeyを使用してTelemetryClientを作成することをお勧めします。詳細は、この[記事](https://cmatskas.com/azure-functions-custom-logging-with-appinsights/)を参照してください。 –
AzureファンクションはすでにApplication Insightと統合されているため、参照されている記事では、それ自体は廃止されています。しかし、その統合はVisual Studioでは動作しません。VSではログを表示し、ポータルでは表示されません。 – gabomgp