gpt4 book ai didi

c# - 如何通过 REST API 创建 Azure Application Insights 的新实例

转载 作者:太空狗 更新时间:2023-10-30 01:03:16 24 4
gpt4 key购买 nike

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

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

有很多操作可以管理现有帐户,但我找不到用于创建新帐户的操作。

需要明确的是:在 https://portal.azure.com我可以单击新建 > 创建 > 开发人员服务 > 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 "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f9bcbab0adad9c959c949c8d8b80ad9c9894b994909a8b968a969f8dd79a9694" rel="noreferrer noopener nofollow">[email protected]</a>" -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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com