我有兩個項目:一個是MVC4應用程序,另一個是輸出類型類庫。Application Insights
我想讓第二個項目(類庫之一)成爲見解溝通層。
代碼編譯和服務器正常運行。
public static void SaveMetric(string title, double value,
string azureKey, Dictionary<string, string> properties = null)
{
try
{
TelemetryClient telemetry = new TelemetryClient();
telemetry.InstrumentationKey = azureKey;
telemetry.TrackMetric(title, value, properties);
}
catch (Exception ex)
{
var a = "";
}
}
當我打電話給telemetry.TrackMetric
函數時,問題開始。此代碼返回錯誤:
"Object reference not set to an instance of an object."(System.NullReferenceException).
是否可以在類庫項目中使用Microsoft Insights?如果是這樣,我做錯了什麼?
有一些額外的信息需要,它說什麼是空? 'title'或'properties'爲空嗎?當然,似乎'屬性'可能是它的默認參數。什麼是具體抱怨?我知道它在度量標準方法中被標記爲默認值,但我無法確定它是否默認爲null或空集合。 –
Ron Reyer,提前試圖解決這個問題。請參閱我的編輯以獲取更多信息,如果您仍有疑問,請再詢問一次。 –
@RicardoRocha - 如果你解決了你的問題,你應該發佈你的解決方案作爲答案。如果這導致了你一個新的問題,你應該問你的新問題作爲一個新的SO問題。 –