Exemple #1
0
        public override void Visit(CosmosDiagnosticsContext cosmosDiagnosticsContext)
        {
            this.jsonWriter.WriteStartObject();

            this.jsonWriter.WritePropertyName("DiagnosticVersion");
            this.jsonWriter.WriteValue(DiagnosticsVersion);

            this.jsonWriter.WritePropertyName("Summary");
            this.jsonWriter.WriteStartObject();
            this.jsonWriter.WritePropertyName("StartUtc");
            this.jsonWriter.WriteValue(cosmosDiagnosticsContext.StartUtc.ToString("o", CultureInfo.InvariantCulture));

            if (cosmosDiagnosticsContext.TryGetTotalElapsedTime(out TimeSpan totalElapsedTime))
            {
                this.jsonWriter.WritePropertyName("TotalElapsedTimeInMs");
                this.jsonWriter.WriteValue(totalElapsedTime.TotalMilliseconds);
            }
            else
            {
                this.jsonWriter.WritePropertyName("RunningElapsedTimeInMs");
                this.jsonWriter.WriteValue(cosmosDiagnosticsContext.GetRunningElapsedTime().TotalMilliseconds);
            }

            this.jsonWriter.WritePropertyName("UserAgent");
            this.jsonWriter.WriteValue(cosmosDiagnosticsContext.UserAgent);

            this.jsonWriter.WritePropertyName("TotalRequestCount");
            this.jsonWriter.WriteValue(cosmosDiagnosticsContext.GetTotalResponseCount());

            this.jsonWriter.WritePropertyName("FailedRequestCount");
            this.jsonWriter.WriteValue(cosmosDiagnosticsContext.GetFailedResponseCount());

            this.jsonWriter.WritePropertyName("Operation");
            this.jsonWriter.WriteValue(cosmosDiagnosticsContext.OperationName);

            this.jsonWriter.WriteEndObject();

            this.jsonWriter.WritePropertyName("Context");
            this.jsonWriter.WriteStartArray();

            foreach (CosmosDiagnosticsInternal cosmosDiagnosticsInternal in cosmosDiagnosticsContext)
            {
                cosmosDiagnosticsInternal.Accept(this);
            }

            this.jsonWriter.WriteEndArray();

            this.jsonWriter.WriteEndObject();
        }