2016-08-08 30 views
0

Ich habe eine Konsolenanwendung, von der ich benutzerdefinierte Ereignisse an meine Application Insight senden möchte. Ich möchte Application Insight NLog Ziel (https://www.nuget.org/packages/Microsoft.ApplicationInsights.NLogTarget/) verwenden, aber es funktioniert nicht. Ich habe versucht, es über CONFIG-Datei zu setzen und versuchte es auch manuell einstellen:Anwendung Einblick NLog Ziel

var config = new LoggingConfiguration(); 
    ConfigurationItemFactory.Default.Targets.RegisterDefinition("ai", typeof(ApplicationInsightsTarget)); 
    ApplicationInsightsTarget aiTarget = new ApplicationInsightsTarget(); 
    aiTarget.InstrumentationKey = "my_key"; 
    aiTarget.Name = "aiTarget"; 
    LoggingRule rule = new LoggingRule("*", LogLevel.Info, aiTarget); 
    config.AddTarget("aiTarget", aiTarget); 
    config.LoggingRules.Add(rule); 
    LogManager.Configuration = config; 

aber immer noch nichts, ich kann nicht meine Ausnahmen oder Ereignisse in Anwendung Einsichten sehen. Irgendwelche Ideen?

Antwort

0

Ich nehme an, Sie Dokumentation gefolgt here (was ziemlich nahe ist, was Sie implementiert):

var config = new LoggingConfiguration(); 

ApplicationInsightsTarget target = new ApplicationInsightsTarget(); 
// You need this only if you did not define InstrumentationKey in ApplicationInsights.config or want to use different instrumentation key 
target.InstrumentationKey = "Your_Resource_Key"; 

LoggingRule rule = new LoggingRule("*", LogLevel.Trace, target); 
config.LoggingRules.Add(rule); 

LogManager.Configuration = config; 

Logger logger = LogManager.GetLogger("Example"); 

logger.Trace("trace log message"); 

Dann würde ich überprüfen mit Fiddler, wenn etwas aus der Box zu dc.services gesendet wird. visualstudio.com und was ist der Antwortcode? Das könnte einen Hinweis auf das Problem geben, wenn das Problem tatsächlich beim Transport, aber nicht bei der Sammlung liegt.

Wenn das Problem in der Sammlung ist, können Sie es beheben lokal mit PerfView and other Diagnostics tools.

PerfView Befehl AI Spuren sammeln würde wie folgt aussehen:

PerfView.exe /onlyProviders=*Microsoft-ApplicationInsights-Extensibility-Web,*Microsoft-ApplicationInsights-Web,*Microsoft-ApplicationInsights-Core,*Microsoft-ApplicationInsights-Extensibility-DependencyCollector,*Microsoft-ApplicationInsights-Extensibility-Rtia-SharedCore,*Microsoft-ApplicationInsights-Extensibility-WindowsServer,*Microsoft-ApplicationInsights-WindowsServer-TelemetryChannel collect 
0

Für meine Konsolenanwendung Ich habe „INSTRUMENTATIONKEY“ von App.config zur Laufzeit.

Zuerst habe ich "APPINSIGHTS_INSTRUMENTATIONKEY" als Schlüssel in App.config hinzugefügt.

Dann lesen und setzen Sie diesen Schlüssel auf Hauptfunktion, indem Sie die folgenden Zeilen hinzufügen.

var key = ConfigurationManager.AppSettings["APPINSIGHTS_INSTRUMENTATIONKEY"]; 
Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Active.InstrumentationKey = key; 

Dann am Ende Sie Hauptfunktion oder in der Schließfunktion ein Thread.Sleep zu geben einige Zeit fügen Sie Daten zu Praktischer Anwendung zu senden.

System.Threading.Thread.Sleep(70000);