Repository: dotnet/runtime
File: src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs (C#)

Code before:
                m_name = eventSourceName;
                m_guid = eventSourceGuid;

                // Enable Implicit Activity tracker
                m_activityTracker = ActivityTracker.Instance;

#if !DEBUG
                if (ProviderMetadata.Length == 0)
#endif
                {
                    // Create and register our provider traits.  We do this early because it is needed to log errors
                    // In the self-describing event case.
                    InitializeProviderMetadata();
                }

                // Register the provider with ETW
                Func<EventSource?> eventSourceFactory = () => this;
                OverrideEventProvider? etwProvider = EventSourceInitHelper.TryGetPreregisteredEtwProvider(eventSourceGuid);
                if (etwProvider == null)
                {
                    etwProvider = new OverrideEventProvider(eventSourceFactory, EventProviderType.ETW);
                    etwProvider.Register(eventSourceGuid, eventSourceName);
    #if TARGET_WINDOWS
                    // API available on OS >= Win 8 and patched Win 7.
                    // Disable only for FrameworkEventSource to avoid recursion inside exception handling.
                    if (this.Name != "System.Diagnostics.Eventing.FrameworkEventSource")
                    {
                        var providerMetadata = ProviderMetadata;
                        fixed (byte* pMetadata = providerMetadata)
                        {
                            etwProvider.SetInformation(
                                Interop.Advapi32.EVENT_INFO_CLASS.SetTraits,
                                pMetadata,
                                (uint)providerMetadata.Length);
                        }
                    }
    #endif // TARGET_WINDOWS
                }

#if FEATURE_PERFTRACING
                // Register the provider with EventPipe
                OverrideEventProvider? eventPipeProvider = EventSourceInitHelper.TryGetPreregisteredEventPipeProvider(eventSourceName);
                if (eventPipeProvider == null)
                {
                    eventPipeProvider = new OverrideEventProvider(eventSourceFactory, EventProviderType.EventPipe);
                    eventPipeProvider.Register(eventSourceGuid, eventSourceName);

                }
#endif
                // Add the eventSource to the global (weak) list.
                // This also sets m_id, which is the index in the list.

Review comment (suggestion):
@copilot `Environment.IsWindows8OrAbove` is always true.  It means that this condition is always true and it can be deleted. Also, delete the comment above since it is no longer applicable

Code after:
                m_name = eventSourceName;
                m_guid = eventSourceGuid;

                // Enable Implicit Activity tracker
                m_activityTracker = ActivityTracker.Instance;

#if !DEBUG
                if (ProviderMetadata.Length == 0)
#endif
                {
                    // Create and register our provider traits.  We do this early because it is needed to log errors
                    // In the self-describing event case.
                    InitializeProviderMetadata();
                }

                // Register the provider with ETW
                Func<EventSource?> eventSourceFactory = () => this;
                OverrideEventProvider? etwProvider = EventSourceInitHelper.TryGetPreregisteredEtwProvider(eventSourceGuid);
                if (etwProvider == null)
                {
                    etwProvider = new OverrideEventProvider(eventSourceFactory, EventProviderType.ETW);
                    etwProvider.Register(eventSourceGuid, eventSourceName);
    #if TARGET_WINDOWS
                    var providerMetadata = ProviderMetadata;
                    fixed (byte* pMetadata = providerMetadata)
                    {
                        etwProvider.SetInformation(
                            Interop.Advapi32.EVENT_INFO_CLASS.SetTraits,
                            pMetadata,
                            (uint)providerMetadata.Length);
                    }
    #endif // TARGET_WINDOWS
                }

#if FEATURE_PERFTRACING
                // Register the provider with EventPipe
                OverrideEventProvider? eventPipeProvider = EventSourceInitHelper.TryGetPreregisteredEventPipeProvider(eventSourceName);
                if (eventPipeProvider == null)
                {
                    eventPipeProvider = new OverrideEventProvider(eventSourceFactory, EventProviderType.EventPipe);
                    eventPipeProvider.Register(eventSourceGuid, eventSourceName);

                }
#endif
                // Add the eventSource to the global (weak) list.
                // This also sets m_id, which is the index in the list.
                EventListener.AddEventSource(this);

                // OK if we get this far without an exception, then we can at least write out error messages.
                // Set m_provider, which allows this.
                m_etwProvider = etwProvider;