2016-01-27 2 views
3

Я написал собственный регистратор для приложения Insights в своем приложении. Я не вижу никаких исключений или ЛЮБЫХ событий при просмотре App Insights на Azure Portal. Вот код класса logger, когда я отлаживаю код, я вижу ключ, присвоенный свойству InstrumentationKey, любые идеи, что я делаю неправильно здесь? Нужно ли мне прикреплять другую информацию к клиенту или конфигурации?Application Insights - исключения для регистрации

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); 
    } 
} 

ответ

6

Я создал новое консольное приложение, установленный последнюю стабильную ApplicationInsights SDK и в значительной степени держал свой пример, с незначительным, но важным различием - я либо позволить подождать перед выключением после вызова TrackException или добавить TelemetryClient.Flush()

namespace logtest 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      AppInsightsLogger logger = new AppInsightsLogger(); 
      logger.LogException(new InvalidOperationException("Is data showing?")); 

      // either wait for a couple of minutes for the batch to be sent of add ai.Flush() after ai.TrackException() to send the batch immediately 
      Console.ReadLine(); 
     } 
    } 

    public class AppInsightsLogger 
    { 
     private TelemetryClient ai; 

     public AppInsightsLogger() 
     { 
      ai = new TelemetryClient(); 
      if (string.IsNullOrEmpty(ai.InstrumentationKey)) 
      { 
       // attempt to load instrumentation key from app settings 
       var appSettingsTiKey = "<ikey>"; 
       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); 
      // ai.Flush(); 
     } 
    } 
} 

Сначала я мог видеть пункт телеметрического послан в окне вывода Visual Studio отладки: enter image description here

Тогда я мог видеть телеметрию оставив свою машину в Fidd Кроме того, я также видел, что это было успешно принято нашей конечной точкой сбора данных. enter image description here

И, наконец, я мог видеть его на портале:

enter image description here

Смежные вопросы