/// <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> public void ReportEvent(string area, string eventName, object parameters = null) { if (string.IsNullOrEmpty(area)) { throw new ArgumentException(nameof(area)); } if (string.IsNullOrEmpty(eventName)) { throw new ArgumentException(nameof(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 = DictionaryExtension.FromAnonymousObject(parameters); IDictionary <string, object> dictWithPrefix = new Dictionary <string, object>(); foreach (KeyValuePair <string, object> kvp in dict) { if (string.IsNullOrEmpty(kvp.Key)) { throw new ArgumentException("parameterName"); } dictWithPrefix[this.PropertyNamePrefix + area.ToString() + "." + kvp.Key] = kvp.Value ?? string.Empty; } this.TelemetryRecorder.RecordEvent(completeEventName, dictWithPrefix); } }
/// <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 = DictionaryExtension.FromAnonymousObject(parameters); foreach (KeyValuePair <string, object> kvp in dict) { telemetryEvent.Properties[kvp.Key] = kvp.Value; } } } _session.PostEvent(telemetryEvent); } }