3
我在應用程序中爲Application Insights編寫了自定義記錄器。在Azure門戶中查看App Insights時,我沒有看到任何異常或任何事件。這裏是記錄器類的代碼,當我調試代碼時,我看到一個分配給InstrumentationKey屬性的鍵,有什麼想法我在這裏做錯了?我是否需要將其他信息附加到客戶端或配置?應用程序洞察 - 記錄異常
public class AppInsightsLogger:ILogger
{
private TelemetryClient ai;
public AppInsightsLogger()
{
ai = new TelemetryClient();
if (string.IsNullOrEmpty(ai.InstrumentationKey))
{
// attempt to load instrumentation key from app settings
var appSettingsTiKey = AppSettings.InsightsKey;
if (!string.IsNullOrEmpty(appSettingsTiKey))
{
TelemetryConfiguration.Active.InstrumentationKey = appSettingsTiKey;
ai.InstrumentationKey = appSettingsTiKey;
}
else
{
throw new Exception("Could not find instrumentation key for Application Insights");
}
}
}
public void LogException(Exception ex)
{
ai.TrackException(ex);
}
}