Ejemplo n.º 1
0
        private static void Track(string sourceName, string message, object payload, TelemetryClient client)
        {
            var telemetry = new TraceTelemetry(message, SeverityLevel.Information);

            telemetry.Properties.Add("DiagnosticSource", sourceName);

            // Transfer properties from payload to telemetry
            if (payload != null)
            {
                foreach (var property in DeclaredPropertiesCache.GetDeclaredProperties(payload))
                {
                    if (!property.IsSpecialName)
                    {
                        telemetry.Properties.Add(property.Name, Convert.ToString(property.GetValue(payload), CultureInfo.InvariantCulture));
                    }
                }
            }

            client.TrackTrace(telemetry);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Observes an event from the diagnostic source and logs it as a message to Application Insights.
        /// </summary>
        /// <param name="event">The event (message and payload) from the diagnostic source.</param>
        public void OnNext(KeyValuePair <string, object> @event)
        {
            var message = @event.Key;
            var payload = @event.Value;

            var telemetry = new TraceTelemetry(message, SeverityLevel.Information);

            telemetry.Properties.Add("DiagnosticSource", this.listenerName);

            // Transfer properties from payload to telemetry
            if (payload != null)
            {
                foreach (var property in DeclaredPropertiesCache.GetDeclaredProperties(payload))
                {
                    if (!property.IsSpecialName)
                    {
                        telemetry.Properties.Add(property.Name, property.GetValue(payload).ToString());
                    }
                }
            }

            this.telemetryClient.TrackTrace(telemetry);
        }