55
66using System ;
77using System . Collections . Generic ;
8- using System . Diagnostics . Tracing ;
98using System . Globalization ;
109using System . IO ;
1110using System . Linq ;
@@ -88,7 +87,7 @@ public override SdkResult Resolve(SdkReference sdkReference, SdkResolverContext
8887 return factory . IndicateFailure ( errors : new List < string > ( ) { Strings . Error_DisabledSdkResolver } , warnings : null ) ;
8988 }
9089
91- if ( NuGetEventSource . IsEnabled ) TraceEvents . ResolveStart ( sdkReference ) ;
90+ if ( SdkResolverEventSource . Instance . IsEnabled ( ) ) SdkResolverEventSource . Instance . ResolveStart ( sdkReference . Name , sdkReference . Version ) ;
9291
9392 try
9493 {
@@ -108,7 +107,7 @@ public override SdkResult Resolve(SdkReference sdkReference, SdkResolverContext
108107 }
109108 finally
110109 {
111- if ( NuGetEventSource . IsEnabled ) TraceEvents . ResolveStop ( sdkReference ) ;
110+ if ( SdkResolverEventSource . Instance . IsEnabled ( ) ) SdkResolverEventSource . Instance . ResolveStop ( sdkReference . Name , sdkReference . Version ) ;
112111 }
113112 }
114113
@@ -159,13 +158,13 @@ public static SdkResult GetSdkResult(SdkReference sdk, object nuGetVersion, SdkR
159158 // Cast the NuGet version since the caller does not want to consume NuGet classes directly
160159 var parsedSdkVersion = ( NuGetVersion ) nuGetVersion ;
161160
162- if ( NuGetEventSource . IsEnabled ) TraceEvents . GetResultStart ( sdk . Name , parsedSdkVersion . OriginalVersion ) ;
161+ if ( SdkResolverEventSource . Instance . IsEnabled ( ) ) SdkResolverEventSource . Instance . GetResultStart ( sdk . Name , parsedSdkVersion . OriginalVersion ) ;
163162
164163 SdkResult result = null ;
165164
166165 try
167166 {
168- if ( NuGetEventSource . IsEnabled ) TraceEvents . LoadSettingsStart ( ) ;
167+ if ( SdkResolverEventSource . Instance . IsEnabled ( ) ) SdkResolverEventSource . Instance . LoadSettingsStart ( ) ;
169168
170169 // Load NuGet settings and a path resolver
171170 ISettings settings ;
@@ -183,7 +182,7 @@ public static SdkResult GetSdkResult(SdkReference sdk, object nuGetVersion, SdkR
183182 }
184183 finally
185184 {
186- if ( NuGetEventSource . IsEnabled ) TraceEvents . LoadSettingsStop ( ) ;
185+ if ( SdkResolverEventSource . Instance . IsEnabled ( ) ) SdkResolverEventSource . Instance . LoadSettingsStop ( ) ;
187186 }
188187
189188 var fallbackPackagePathResolver = new FallbackPackagePathResolver ( NuGetPathContext . Create ( settings ) ) ;
@@ -201,7 +200,7 @@ public static SdkResult GetSdkResult(SdkReference sdk, object nuGetVersion, SdkR
201200 X509TrustStore . InitializeForDotNetSdk ( logger ) ;
202201#endif
203202
204- if ( NuGetEventSource . IsEnabled ) TraceEvents . RestorePackageStart ( libraryIdentity ) ;
203+ if ( SdkResolverEventSource . Instance . IsEnabled ( ) ) SdkResolverEventSource . Instance . RestorePackageStart ( libraryIdentity . Name , libraryIdentity . Version . OriginalVersion ) ;
205204
206205 // Asynchronously run the restore without a commit which find the package on configured feeds, download, and unzip it without generating any other files
207206 // This must be run in its own task because legacy project system evaluates projects on the UI thread which can cause RunWithoutCommit() to deadlock
@@ -213,7 +212,7 @@ public static SdkResult GetSdkResult(SdkReference sdk, object nuGetVersion, SdkR
213212
214213 var results = restoreTask . Result ;
215214
216- if ( NuGetEventSource . IsEnabled ) TraceEvents . RestorePackageStop ( libraryIdentity ) ;
215+ if ( SdkResolverEventSource . Instance . IsEnabled ( ) ) SdkResolverEventSource . Instance . RestorePackageStop ( libraryIdentity . Name , libraryIdentity . Version . OriginalVersion ) ;
217216
218217 fallbackPackagePathResolver = new FallbackPackagePathResolver ( NuGetPathContext . Create ( settings ) ) ;
219218
@@ -266,7 +265,7 @@ public static SdkResult GetSdkResult(SdkReference sdk, object nuGetVersion, SdkR
266265 }
267266 finally
268267 {
269- if ( NuGetEventSource . IsEnabled ) TraceEvents . GetResultStop ( sdk . Name , parsedSdkVersion . OriginalVersion , result ) ;
268+ if ( SdkResolverEventSource . Instance . IsEnabled ( ) ) SdkResolverEventSource . Instance . GetResultStop ( sdk . Name , parsedSdkVersion . OriginalVersion , result ? . Path , result == null ? 0 : ( result . Success ? 1 : 0 ) ) ;
270269 }
271270 }
272271
@@ -317,121 +316,5 @@ private static bool TryGetMSBuildSdkPackageInfo(FallbackPackagePathResolver fall
317316 return true ;
318317 }
319318 }
320-
321- private static class TraceEvents
322- {
323- private const string EventNameGetResult = "SdkResolver/GetResult" ;
324- private const string EventNameLoadSettings = "SdkResolver/LoadSettings" ;
325- private const string EventNameResolve = "SdkResolver/Resolve" ;
326- private const string EventNameRestorePackage = "SdkResolver/RestorePackage" ;
327-
328- public static void GetResultStart ( string id , string version )
329- {
330- var eventOptions = new EventSourceOptions
331- {
332- ActivityOptions = EventActivityOptions . Detachable ,
333- Keywords = NuGetEventSource . Keywords . Performance | NuGetEventSource . Keywords . SdkResolver ,
334- Opcode = EventOpcode . Start
335- } ;
336-
337- NuGetEventSource . Instance . Write ( EventNameGetResult , eventOptions , new GetResultStartEventData ( id , version ) ) ;
338- }
339-
340- public static void GetResultStop ( string id , string version , SdkResult result )
341- {
342- var eventOptions = new EventSourceOptions
343- {
344- ActivityOptions = EventActivityOptions . Detachable ,
345- Keywords = NuGetEventSource . Keywords . Performance | NuGetEventSource . Keywords . SdkResolver ,
346- Opcode = EventOpcode . Stop
347- } ;
348-
349- NuGetEventSource . Instance . Write ( EventNameGetResult , eventOptions , new GetResultStopEventData ( id , version , InstallPath : result ? . Path , Success : result == null ? false : result . Success ) ) ;
350- }
351-
352- public static void LoadSettingsStart ( )
353- {
354- var eventOptions = new EventSourceOptions
355- {
356- ActivityOptions = EventActivityOptions . Detachable ,
357- Keywords = NuGetEventSource . Keywords . Performance | NuGetEventSource . Keywords . SdkResolver ,
358- Opcode = EventOpcode . Start
359- } ;
360-
361- NuGetEventSource . Instance . Write ( EventNameLoadSettings , eventOptions ) ;
362- }
363-
364- public static void LoadSettingsStop ( )
365- {
366- var eventOptions = new EventSourceOptions
367- {
368- ActivityOptions = EventActivityOptions . Detachable ,
369- Keywords = NuGetEventSource . Keywords . Performance | NuGetEventSource . Keywords . SdkResolver ,
370- Opcode = EventOpcode . Stop
371- } ;
372-
373- NuGetEventSource . Instance . Write ( EventNameLoadSettings , eventOptions ) ;
374- }
375-
376- public static void ResolveStart ( SdkReference sdkReference )
377- {
378- var eventOptions = new EventSourceOptions
379- {
380- ActivityOptions = EventActivityOptions . Detachable ,
381- Keywords = NuGetEventSource . Keywords . SdkResolver | NuGetEventSource . Keywords . Performance ,
382- Opcode = EventOpcode . Start
383- } ;
384-
385- NuGetEventSource . Instance . Write ( EventNameResolve , eventOptions , new ResolveEventData ( sdkReference . Name , sdkReference . Version ) ) ;
386- }
387-
388- public static void ResolveStop ( SdkReference sdkReference )
389- {
390- var eventData = new EventSourceOptions
391- {
392- ActivityOptions = EventActivityOptions . Detachable ,
393- Keywords = NuGetEventSource . Keywords . SdkResolver | NuGetEventSource . Keywords . Performance ,
394- Opcode = EventOpcode . Stop
395- } ;
396-
397- NuGetEventSource . Instance . Write ( EventNameResolve , eventData , new ResolveEventData ( sdkReference . Name , sdkReference . Version ) ) ;
398- }
399-
400- public static void RestorePackageStart ( LibraryIdentity libraryIdentity )
401- {
402- var eventOptions = new EventSourceOptions
403- {
404- ActivityOptions = EventActivityOptions . Detachable ,
405- Keywords = NuGetEventSource . Keywords . Performance | NuGetEventSource . Keywords . SdkResolver ,
406- Opcode = EventOpcode . Start
407- } ;
408-
409- NuGetEventSource . Instance . Write ( EventNameRestorePackage , eventOptions , new RestorePackageEventData ( libraryIdentity . Name , libraryIdentity . Version . OriginalVersion ) ) ;
410- }
411-
412- public static void RestorePackageStop ( LibraryIdentity libraryIdentity )
413- {
414- var eventOptions = new EventSourceOptions
415- {
416- ActivityOptions = EventActivityOptions . Detachable ,
417- Keywords = NuGetEventSource . Keywords . Performance | NuGetEventSource . Keywords . SdkResolver ,
418- Opcode = EventOpcode . Stop
419- } ;
420-
421- NuGetEventSource . Instance . Write ( EventNameRestorePackage , eventOptions , new RestorePackageEventData ( libraryIdentity . Name , libraryIdentity . Version . OriginalVersion ) ) ;
422- }
423-
424- [ EventData ]
425- private record struct GetResultStartEventData ( string Id , string Version ) ;
426-
427- [ EventData ]
428- private record struct GetResultStopEventData ( string Id , string Version , string InstallPath , bool Success ) ;
429-
430- [ EventData ]
431- private record struct ResolveEventData ( string Name , string Version ) ;
432-
433- [ EventData ]
434- private record struct RestorePackageEventData ( string Id , string Version ) ;
435- }
436319 }
437320}
0 commit comments