/// <summary> /// Formats the event. /// </summary> /// <param name="properties">The properties.</param> /// <param name="metrics">The metrics.</param> /// <returns>System.String.</returns> public string FormatEvent(Dictionary <string, string> properties, Dictionary <string, double> metrics = null) { //make sure we have at least an empty dictionary so that remainder of code needn't branch if (null == metrics) { metrics = new Dictionary <string, double>(); } //build up JSON representation of the arbitrary dictionaries passed in var jsonObject = new JObject( new JProperty("properties", new JArray( from p in properties select new JObject(new JProperty(p.Key, p.Value)) ) ), new JProperty("metrics", new JArray( from m in metrics select new JObject(new JProperty(m.Key, m.Value))) ) ); var record = new TelemetryData { RecordType = "trace", TraceName = "trace", TraceJson = $"{jsonObject.ToString(Formatting.None)}" }; return(record.AsStringWith(_context)); }