我想为 ASP.Net Web 应用程序自动设置 Azure Application Insights 帐户。

我已经安装了 nuget 包:Install-Package Microsoft.Azure.Insights -Pre现在我在看 Microsoft.Azure.Management.Insights.InsightsManagementClient

管理现有帐户有很多操作,除了我找不到创建新帐户的操作。

需要明确的是:在 https://portal.azure.com 上,我可以点击 New > Create > Developer Services > Application Insights 。我如何在 c# 中做到这一点?

最佳答案

这是 Eric Mattingly 创建的脚本(您需要安装 Azure PowerShell 才能工作):

Output:
App Insights Name =  erimattestapp
IKey =  00000000-0000-0000-0000-000000000000

Script:
cls

##################################################################
# Set Values
##################################################################

#If running manually, comment this out to before the first execution to login to the Azure Portal
#Add-AzureAccount

#Set the name of the Application Insights Resource
$appInsightsName = "erimatTestApp"

#Set the application name used for the value of the Tag "AppInsightsApp" - http://azure.microsoft.com/en-us/documentation/articles/azure-preview-portal-using-tags/
$applicationTagName = "erimatTestApp"

#Set the name of the Resource Group to use.  By default will use the application Name as a starter
$resourceGroupName = "erimatTestAppRG"

##################################################################
# Create the Resource and Output the name and iKey
##################################################################
#Set the script to Resource Manager - http://azure.microsoft.com/en-us/documentation/articles/powershell-azure-resource-manager/
Switch-AzureMode AzureResourceManager

#Select the azure subscription
Select-AzureSubscription -SubscriptionName "ECIT Preproduction Monitoring"

#Create the App Insights Resource
$resource = New-AzureResource -Name $appInsightsName -ResourceGroupName $resourceGroupName -Tag @{ Name = "AppInsightsApp"; Value = $applicationTagName} -ResourceType "Microsoft.Insights/Components" -Location "Central US" -ApiVersion "2014-08-01"

#Give team owner access - http://azure.microsoft.com/en-us/documentation/articles/role-based-access-control-powershell/
New-AzureRoleAssignment -Mail "[email protected]" -RoleDefinitionName Owner -Scope $resource.ResourceId | Out-Null

#Display iKey
Write-Host "App Insights Name = " $resource.Properties["Name"]
Write-Host "IKey = " $resource.Properties["InstrumentationKey"]

关于c# - 如何通过 REST API 创建 Azure Application Insights 的新实例,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30021650/

10-11 05:07