4
4
using System ;
5
5
using System . Collections ;
6
6
using System . Collections . Generic ;
7
- using System . Diagnostics ;
8
7
using System . Globalization ;
9
8
using System . Reflection ;
10
9
using Microsoft . AspNetCore . Http ;
@@ -14,9 +13,9 @@ namespace Microsoft.AspNetCore.Hosting
14
13
{
15
14
internal static class HostingLoggerExtensions
16
15
{
17
- public static IDisposable RequestScope ( this ILogger logger , HttpContext httpContext , Activity activity )
16
+ public static IDisposable RequestScope ( this ILogger logger , HttpContext httpContext , string activityId )
18
17
{
19
- return logger . BeginScope ( new HostingLogScope ( httpContext , activity ) ) ;
18
+ return logger . BeginScope ( new HostingLogScope ( httpContext , activityId ) ) ;
20
19
}
21
20
22
21
public static void ApplicationError ( this ILogger logger , Exception exception )
@@ -97,15 +96,15 @@ private class HostingLogScope : IReadOnlyList<KeyValuePair<string, object>>
97
96
{
98
97
private readonly string _path ;
99
98
private readonly string _traceIdentifier ;
100
- private readonly Activity _activity ;
99
+ private readonly string _activityId ;
101
100
102
101
private string _cachedToString ;
103
102
104
103
public int Count
105
104
{
106
105
get
107
106
{
108
- return 5 ;
107
+ return 3 ;
109
108
}
110
109
}
111
110
@@ -123,29 +122,20 @@ public KeyValuePair<string, object> this[int index]
123
122
}
124
123
else if ( index == 2 )
125
124
{
126
- return new KeyValuePair < string , object > ( "SpanId" , _activity . GetSpanId ( ) ) ;
127
- }
128
- else if ( index == 3 )
129
- {
130
- return new KeyValuePair < string , object > ( "TraceId" , _activity . GetTraceId ( ) ) ;
131
- }
132
- else if ( index == 4 )
133
- {
134
- return new KeyValuePair < string , object > ( "ParentId" , _activity . GetParentId ( ) ) ;
125
+ return new KeyValuePair < string , object > ( "ActivityId" , _activityId ) ;
135
126
}
136
127
137
128
throw new ArgumentOutOfRangeException ( nameof ( index ) ) ;
138
129
}
139
130
}
140
131
141
- public HostingLogScope ( HttpContext httpContext , Activity activity )
132
+ public HostingLogScope ( HttpContext httpContext , string activityId )
142
133
{
143
134
_traceIdentifier = httpContext . TraceIdentifier ;
144
135
_path = ( httpContext . Request . PathBase . HasValue
145
136
? httpContext . Request . PathBase + httpContext . Request . Path
146
137
: httpContext . Request . Path ) . ToString ( ) ;
147
-
148
- _activity = activity ;
138
+ _activityId = activityId ;
149
139
}
150
140
151
141
public override string ToString ( )
@@ -154,12 +144,10 @@ public override string ToString()
154
144
{
155
145
_cachedToString = string . Format (
156
146
CultureInfo . InvariantCulture ,
157
- "RequestPath:{0} RequestId:{1}, SpanId :{2}, TraceId:{3}, ParentId:{4 }" ,
147
+ "RequestPath:{0} RequestId:{1}, ActivityId :{2}" ,
158
148
_path ,
159
149
_traceIdentifier ,
160
- _activity . GetSpanId ( ) ,
161
- _activity . GetTraceId ( ) ,
162
- _activity . GetParentId ( ) ) ;
150
+ _activityId ) ;
163
151
}
164
152
165
153
return _cachedToString ;
0 commit comments