Azure Runbook 加载 .Net 程序集以获得应用程序洞察 [英] Azure Runbook load .Net assembly for application insight

查看:35
本文介绍了Azure Runbook 加载 .Net 程序集以获得应用程序洞察的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要求,我想将一些指标写入应用程序洞察中,以便定期监控服务.

I have requirement where I want to write some metrics to the application insight for monitoring a service at a regular interval.

我想我会编写这个 PowerShell 脚本并相应地安排它.

I though that I would write this PowerShell script and schedule it accordingly.

Write-Output "Script Start"
$PSScriptRoot = Get-Location
$AI = "$PSScriptRootMicrosoft.ApplicationInsights.dll"
[Reflection.Assembly]::LoadFile("$AI")
$InstrumentationKey = ""
$TelClient = New-Object "Microsoft.ApplicationInsights.TelemetryClient"
$TelClient.InstrumentationKey = $InstrumentationKey

$TrackMetric = New-Object "Microsoft.ApplicationInsights.DataContracts.MetricTelemetry"
$TrackMetric.Name = "PowershellTest"
$TrackMetric.Value = Get-Random -Minimum:1 -Maximum:100

$TelClient.TrackMetric($TrackMetric)
$TelClient.Flush()

Write-Output "Script End  $TrackMetric.Value"

此 PowerShell 脚本有效,但在我将该脚本移至 Runbook 后,它不再有效.

This PowerShell Script works, but after I moving that script to Runbook it is no longer working.

所以,问题来了.我无法在 Runbook 中加载 ApplicationInsight DLL.

So, here is the issue. I am not able to load the ApplicationInsight DLL inside the Runbook.

知道怎么做吗?

Exception calling "LoadFile" with "1" argument(s): "The system cannot find the file specified. (Exception from HRESULT: 
0x80070002)"

谢谢希拉吉

推荐答案

尝试以下程序集的路径"C:ModulesGlobalAzureComputeMicrosoft.ApplicationInsights.dll"

Try following path for the assembly "C:ModulesGlobalAzureComputeMicrosoft.ApplicationInsights.dll"

这篇关于Azure Runbook 加载 .Net 程序集以获得应用程序洞察的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆