我需要使用 C# 代码检索应用程序见解的检测密钥



我使用ARM模板和c#代码创建了应用程序Insights

var creds = new AzureCredentialsFactory().FromServicePrincipal(client, key, tenant, AzureEnvironment.AzureGlobalCloud);

IAzure azure = Microsoft.Azure.Management.Fluent.Azure.Authenticate(creds).WithSubscription(subscription);
IDeployment deployement = azure.Deployments.Define("my-app")
.WithExistingResourceGroup("my-rg-grp")
.WithTemplate(template)
.WithParameters("{}")
.WithMode(DeploymentMode.Incremental)
.CreateAsync();

部署响应中没有InstrumentationKey

我如何在使用ARM创建应用程序洞察后获得InstrumentationKey ?

您可以使用ApplicationInsightsManagementClient类来获取ApplicationInsights资源和相关属性。这个类是在Microsoft.Azure.Management.ApplicationInsights v0.3.0-preview package

中定义的。
ApplicationInsightsManagementClient applicationInsightsManagementClient = 
new ApplicationInsightsManagementClient(creds) { SubscriptionId = subscriptionId };
var appliationInsightComponents = await applicationInsightsManagementClient.Components.ListAsync();
var requiredApplicationInsightComponent = appliationInsightComponents.SingleOrDefault(a => 
a.ApplicationId.Equals("<<Name of resource>>", StringComparison.OrdinalIgnoreCase));

//使用

获取InstrumentationKeyrequiredApplicationInsightComponent.InstrumentationKey

相关内容

  • 没有找到相关文章

最新更新