Esempio n. 1
0
        /// <summary>
        /// Records event with parameters
        /// </summary>
        /// <param name="area">Telemetry area name such as 'Toolbox'.</param>
        /// <param name="eventName">Event name.</param>
        /// <param name="parameters">
        /// Either string/object dictionary or anonymous
        /// collection of string/object pairs.
        /// </param>
        /// <summary>
        public void ReportEvent(TelemetryArea area, string eventName, object parameters = null)
        {
            Check.ArgumentStringNullOrEmpty("eventName", eventName);

            string completeEventName = MakeEventName(area, eventName);

            if (parameters == null)
            {
                this.TelemetryRecorder.RecordEvent(completeEventName);
            }
            else if (parameters is string)
            {
                this.TelemetryRecorder.RecordEvent(completeEventName, parameters as string);
            }
            else
            {
                IDictionary <string, object> dict           = DictionaryExtensions.FromAnonymousObject(parameters);
                IDictionary <string, object> dictWithPrefix = new Dictionary <string, object>();

                foreach (KeyValuePair <string, object> kvp in dict)
                {
                    Check.ArgumentStringNullOrEmpty("parameterName", kvp.Key);
                    dictWithPrefix[this.PropertyNamePrefix + area.ToString() + "." + kvp.Key] = kvp.Value ?? string.Empty;
                }
                this.TelemetryRecorder.RecordEvent(completeEventName, dictWithPrefix);
            }
        }
Esempio n. 2
0
        public void RecordEvent(string eventName, object parameters = null)
        {
            using (StreamWriter sw = File.AppendText(FileTelemetryRecorder.TestLog)) {
                SimpleTelemetryEvent telemetryEvent = new SimpleTelemetryEvent(eventName);
                telemetryEvent.Properties = DictionaryExtensions.FromAnonymousObject(parameters);

                string json = JsonConvert.SerializeObject(telemetryEvent);
                sw.WriteLine(json);
            }
        }
 public void RecordEvent(string eventName, object parameters = null)
 {
     _stringBuilder.AppendLine(eventName);
     if (parameters != null)
     {
         if (parameters is string)
         {
             WriteProperty("Value", parameters as string);
         }
         else
         {
             WriteDictionary(DictionaryExtensions.FromAnonymousObject(parameters));
         }
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Records event with parameters
 /// </summary>
 public void RecordEvent(string eventName, object parameters = null)
 {
     if (this.IsEnabled)
     {
         TelemetryEvent telemetryEvent = new TelemetryEvent(eventName);
         if (parameters != null)
         {
             var stringParameter = parameters as string;
             if (stringParameter != null)
             {
                 telemetryEvent.Properties["Value"] = stringParameter;
             }
             else
             {
                 IDictionary <string, object> dict = DictionaryExtensions.FromAnonymousObject(parameters);
                 foreach (KeyValuePair <string, object> kvp in dict)
                 {
                     telemetryEvent.Properties[kvp.Key] = kvp.Value;
                 }
             }
         }
         _session.PostEvent(telemetryEvent);
     }
 }