From 71eda6fc72ea082ec4a545d7e890ec65df2ab2b1 Mon Sep 17 00:00:00 2001 From: Sung Yoon Whang Date: Wed, 10 Feb 2021 16:22:10 -0800 Subject: [PATCH] Check whether EventSource is supported before initializing RuntimeEventSource (#48121) --- .../System.Private.CoreLib/src/System/StartupHookProvider.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/coreclr/System.Private.CoreLib/src/System/StartupHookProvider.cs b/src/coreclr/System.Private.CoreLib/src/System/StartupHookProvider.cs index 1ad9233..ef1cbdf 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/StartupHookProvider.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/StartupHookProvider.cs @@ -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) -- 2.7.4