diff --git a/Microsoft.Azure.Cosmos/src/Tracing/TraceWriter.TraceJsonWriter.cs b/Microsoft.Azure.Cosmos/src/Tracing/TraceWriter.TraceJsonWriter.cs index a24b156dea..8ed355e95a 100644 --- a/Microsoft.Azure.Cosmos/src/Tracing/TraceWriter.TraceJsonWriter.cs +++ b/Microsoft.Azure.Cosmos/src/Tracing/TraceWriter.TraceJsonWriter.cs @@ -39,21 +39,19 @@ public static void WriteTrace( writer.WriteFieldName("component"); writer.WriteStringValue(trace.Component.ToString()); -#if INTERNAL - writer.WriteFieldName("caller information"); + writer.WriteFieldName("caller info"); writer.WriteObjectStart(); - writer.WriteFieldName("member name"); + writer.WriteFieldName("member"); writer.WriteStringValue(trace.CallerInfo.MemberName); - writer.WriteFieldName("file path"); - writer.WriteStringValue(trace.CallerInfo.FilePath); + writer.WriteFieldName("file"); + writer.WriteStringValue(GetFileNameFromPath(trace.CallerInfo.FilePath)); - writer.WriteFieldName("line number"); + writer.WriteFieldName("line"); writer.WriteNumber64Value(trace.CallerInfo.LineNumber); writer.WriteObjectEnd(); -#endif writer.WriteFieldName("start time"); writer.WriteStringValue(trace.StartTime.ToString("hh:mm:ss:fff")); diff --git a/Microsoft.Azure.Cosmos/src/Tracing/TraceWriter.TraceTextWriter.cs b/Microsoft.Azure.Cosmos/src/Tracing/TraceWriter.TraceTextWriter.cs index 443c6fc040..247496ed73 100644 --- a/Microsoft.Azure.Cosmos/src/Tracing/TraceWriter.TraceTextWriter.cs +++ b/Microsoft.Azure.Cosmos/src/Tracing/TraceWriter.TraceTextWriter.cs @@ -176,14 +176,13 @@ private static void WriteTraceRecursive( writer.Write("Component"); writer.Write(space); -#if INTERNAL writer.Write(trace.CallerInfo.MemberName); + writer.Write('@'); - writer.Write(trace.CallerInfo.FilePath.Split('\\').Last()); + writer.Write(GetFileNameFromPath(trace.CallerInfo.FilePath)); writer.Write(':'); writer.Write(trace.CallerInfo.LineNumber); writer.Write(space); -#endif writer.Write(trace.StartTime.ToString("hh:mm:ss:fff", CultureInfo.InvariantCulture)); writer.Write(space); diff --git a/Microsoft.Azure.Cosmos/src/Tracing/TraceWriter.cs b/Microsoft.Azure.Cosmos/src/Tracing/TraceWriter.cs index 8937606a2b..4d971a2743 100644 --- a/Microsoft.Azure.Cosmos/src/Tracing/TraceWriter.cs +++ b/Microsoft.Azure.Cosmos/src/Tracing/TraceWriter.cs @@ -4,12 +4,16 @@ namespace Microsoft.Azure.Cosmos.Tracing { + using System.Collections.Generic; using System.IO; + using System.Linq; using System.Text; using Microsoft.Azure.Cosmos.Json; internal static partial class TraceWriter { + private static readonly Dictionary FilePathToName = new Dictionary(); + public static void WriteTrace( TextWriter writer, ITrace trace, @@ -56,5 +60,16 @@ public enum AsciiType ClassicRounded, ExclamationMarks, } + + public static string GetFileNameFromPath(string filePath) + { + if (!FilePathToName.TryGetValue(filePath, out string fileName)) + { + fileName = filePath.Split('\\').Last(); + FilePathToName[filePath] = fileName; + } + + return fileName; + } } } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/EndToEndTraceWriterBaselineTests.BatchOperationsAsync.xml b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/EndToEndTraceWriterBaselineTests.BatchOperationsAsync.xml index 8e11f3eac6..3e781482c1 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/EndToEndTraceWriterBaselineTests.BatchOperationsAsync.xml +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/EndToEndTraceWriterBaselineTests.BatchOperationsAsync.xml @@ -34,29 +34,34 @@ @@ -97,6 +102,11 @@ "name": "Trace For Baseline Testing", "id": "00000000-0000-0000-0000-000000000000", "component": "Unknown", + "caller info": { + "member": "MemberName", + "file": "FilePath", + "line": 42 + }, "start time": "12:00:00:000", "duration in milliseconds": 0, "data": { @@ -135,7 +145,7 @@