Пример #1
0
 /// <summary>
 /// Calls the App Insights TrackMetric method.
 /// </summary>
 private void HandleMetric(TelemetryMetric e)
 {
     try
     {
         this.WriteLine("Tracking metric ({2}): {0}={1}", e.Id, e.Value, e.Framework);
         if (this.Telemetry != null)
         {
             this.PendingEvents = true;
             this.Telemetry.Context.GlobalProperties["dotnet"] = e.Framework;
             this.Telemetry.TrackMetric(new MetricTelemetry(e.Id, e.Value));
         }
     }
     catch (Exception ex)
     {
         this.WriteLine("Error sending TrackMetric: {0}", ex.Message);
     }
 }
Пример #2
0
        public async Task TrackMetricAsync(string name, double value)
        {
            if (!this.Enabled)
            {
                return;
            }

            var e = new TelemetryMetric(this.Framework, name, this.Name, value);

            if (this.Server != null)
            {
                await this.Server.SendReceiveAsync(e);
            }
            else
            {
                // queue the event until the telemetry server is ready.
                lock (this.Pending)
                {
                    this.Pending.Add(e);
                }
            }
        }