/*************************************************************************/
        public async Task WriteTelemetry(Telemetry telemetry)
        {
            await Task.Yield();

            switch (telemetry.Type)
            {
            case Telemetry.TelemetryType.Error:
            {
                var tel = new ExceptionTelemetry(telemetry.Exception);

                tel.MergeProperties(telemetry, _childrenAsJson);
                tel.Message       = telemetry.Exception.Message;
                tel.SeverityLevel = (SeverityLevel)((int)telemetry.Severity);

                SetAttributes(telemetry, tel, tel);

                _client.TrackException(tel);

                break;
            }

            case Telemetry.TelemetryType.Event:
            {
                var tel = new EventTelemetry(telemetry.Message);

                tel.MergeProperties(telemetry, _childrenAsJson);

                SetAttributes(telemetry, tel, tel);

                _client.TrackEvent(tel);

                break;
            }

            case Telemetry.TelemetryType.Metric:
            {
                var tel = new MetricTelemetry(telemetry.Message, telemetry.Value);

                tel.MergeProperties(telemetry, _childrenAsJson);

                SetAttributes(telemetry, tel, tel);

                _client.TrackMetric(tel);

                break;
            }

            case Telemetry.TelemetryType.Trace:
            {
                var tel = new TraceTelemetry(telemetry.Message, (SeverityLevel)((int)telemetry.Severity));

                tel.MergeProperties(telemetry, _childrenAsJson);

                SetAttributes(telemetry, tel, tel);

                _client.TrackTrace(tel);

                break;
            }

            case Telemetry.TelemetryType.Request:
            {
                var tel = new RequestTelemetry(telemetry.Message,
                                               telemetry.Request.StartTime,
                                               telemetry.Request.Duration,
                                               telemetry.Request.ResponseCode,
                                               telemetry.Request.Success);

                tel.MergeProperties(telemetry, _childrenAsJson);

                SetAttributes(telemetry, tel, tel);

                _client.TrackRequest(tel);

                break;
            }
            }

            _client.Flush();

            return;
        }
        private bool TraceInternal(EventSeverity eventSeverity, string message, string codePoint, Dictionary <string, string> data, string callerMemberName, string callerFilePath, int callerLineNumber)
        {
            try
            {
                SeverityLevel sl;

                switch (eventSeverity)
                {
                case EventSeverity.Verbose:
                case EventSeverity.Debug:
                    sl = SeverityLevel.Verbose;
                    break;

                case EventSeverity.Metric:
                case EventSeverity.OperationInfo:
                case EventSeverity.Event:
                case EventSeverity.Info:
                    sl = SeverityLevel.Information;
                    break;

                case EventSeverity.Warning:
                    sl = SeverityLevel.Warning;
                    break;

                case EventSeverity.Error:
                case EventSeverity.OperationError:
                    sl = SeverityLevel.Error;
                    break;

                case EventSeverity.Fatal:
                    sl = SeverityLevel.Critical;
                    break;

                default:
                    sl = SeverityLevel.Verbose;
                    break;
                }

                Dictionary <string, string> props = data.Safe();

                TraceTelemetry tt = new TraceTelemetry()
                {
                    Message       = message,
                    Timestamp     = DateTimeOffset.UtcNow,
                    SeverityLevel = sl
                };

                this.AddCodepoint(message, codePoint, callerMemberName, callerFilePath, callerLineNumber, props);
                this.AddCallerFilePath(callerFilePath, props);
                this.AddCallerLineNumber(callerLineNumber, props);
                this.AddCallerMemberName(callerMemberName, props);

                if (this.EmitAdditionalData)
                {
                    tt.MergeProperties(props);
                }

                // set operational properties
                tt.SetOperationInfo(this);

                this.internalTelemetryClient.TrackTrace(tt);

                return(true);
            }
            catch (Exception ex)
            {
                DiagnosticTrace.Instance.Error("Unexpected error occured when emitting trace.", ex, "7eI+iHZxj0M");

                return(true);
            }
        }