Skip to content

Commit 71eda6f

Browse files
authored
Check whether EventSource is supported before initializing RuntimeEventSource (#48121)
1 parent ba36813 commit 71eda6f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/coreclr/System.Private.CoreLib/src/System/StartupHookProvider.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Diagnostics;
6+
using System.Diagnostics.Tracing;
67
using System.Diagnostics.CodeAnalysis;
78
using System.IO;
89
using System.Reflection;
@@ -31,8 +32,11 @@ private static void ProcessStartupHooks()
3132
if (!IsSupported)
3233
return;
3334

34-
// Initialize tracing before any user code can be called.
35-
System.Diagnostics.Tracing.RuntimeEventSource.Initialize();
35+
// Initialize tracing before any user code can be called if EventSource is enabled.
36+
if (EventSource.IsSupported)
37+
{
38+
System.Diagnostics.Tracing.RuntimeEventSource.Initialize();
39+
}
3640

3741
string? startupHooksVariable = AppContext.GetData("STARTUP_HOOKS") as string;
3842
if (startupHooksVariable == null)

0 commit comments

Comments
 (0)