Check whether EventSource is supported before initializing RuntimeEventSource (#48121)
authorSung Yoon Whang <suwhang@microsoft.com>
Thu, 11 Feb 2021 00:22:10 +0000 (16:22 -0800)
committerGitHub <noreply@github.com>
Thu, 11 Feb 2021 00:22:10 +0000 (16:22 -0800)
src/coreclr/System.Private.CoreLib/src/System/StartupHookProvider.cs

index 1ad9233..ef1cbdf 100644 (file)
@@ -3,6 +3,7 @@
 
 using System;
 using System.Diagnostics;
+using System.Diagnostics.Tracing;
 using System.Diagnostics.CodeAnalysis;
 using System.IO;
 using System.Reflection;
@@ -31,8 +32,11 @@ namespace System
             if (!IsSupported)
                 return;
 
-            // Initialize tracing before any user code can be called.
-            System.Diagnostics.Tracing.RuntimeEventSource.Initialize();
+            // Initialize tracing before any user code can be called if EventSource is enabled.
+            if (EventSource.IsSupported)
+            {
+                System.Diagnostics.Tracing.RuntimeEventSource.Initialize();
+            }
 
             string? startupHooksVariable = AppContext.GetData("STARTUP_HOOKS") as string;
             if (startupHooksVariable == null)