/// <summary>
        ///     Writes a trace message to Application Insights.
        /// </summary>
        /// <param name="message">The trace message.</param>
        /// <param name="aiTraceSeverity">The severity level <see cref="AiTraceSeverity" />.</param>
        /// <param name="timestamp">The UTC timestamp of the event (default = DateTime.UtcNow).</param>
        /// <returns><c>true</c> if successfully logged, <c>false</c> otherwise.</returns>
        public bool WriteTrace(string message, AiTraceSeverity aiTraceSeverity, DateTime?timestamp = null)
        {
            if (!this.Log("Trace", this._disableTraceTracking, this._percentLoggedTrace))
            {
                return(true);
            }

            timestamp = timestamp ?? DateTime.UtcNow;

            var aiTrace = new AiTrace(this.EventProperties, message, aiTraceSeverity);

            var json = this.GetTraceJsonString(timestamp.Value, aiTrace);

            if (this._enableDebug)
            {
                this._tracingService.Trace($"DEBUG: Application Insights JSON: {CreateJsonDataLog(json)}");
            }

            return(this.SendToAi(json));
        }
        private string GetTraceJsonString(DateTime timestamp, AiTrace aiTrace)
        {
            var logRequest = new AiLogRequest
            {
                Name = $"Microsoft.ApplicationInsights.{this._instrumentationKey}.Message",
                Time = timestamp.ToString("O"),
                InstrumentationKey = this._instrumentationKey,
                Tags = new AiTags
                {
                    OperationName       = null,
                    RoleInstance        = null,
                    AuthenticatedUserId = this._authenticatedUserId
                },
                Data = new AiData {
                    BaseType = "MessageData", BaseData = aiTrace
                }
            };

            var json = SerializationHelper.SerializeObject <AiLogRequest>(logRequest);

            return(json);
        }