diff --git a/Directory.Build.props b/Directory.Build.props index 99eee260233d71..84877200392e0c 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -319,6 +319,8 @@ $(NoWarn);CS8625 $(NoWarn);CS8617 + + $(NoWarn);ESGEN001;ESGEN002 none @@ -360,6 +362,8 @@ $(NoWarn);SYSLIB0011;SYSLIB0050;SYSLIB0051 $(NoWarn);IL2121 + + $(NoWarn);ESGEN001;ESGEN002 annotations diff --git a/eng/generators.targets b/eng/generators.targets index 1a25554a78f1b5..c24eca9be55dd1 100644 --- a/eng/generators.targets +++ b/eng/generators.targets @@ -40,6 +40,12 @@ '$(DisableImplicitFrameworkReferences)' == 'true' and '@(ProjectReference->AnyHaveMetadataValue('Filename', 'System.Runtime.InteropServices'))' == 'true' )" /> + + + > _providers = new(); + // This event source uses EtwSelfDescribingEventFormat for backward compatibility. private DependencyInjectionEventSource() : base(EventSourceSettings.EtwSelfDescribingEventFormat) { } diff --git a/src/libraries/Microsoft.Extensions.Logging.EventSource/src/LoggingEventSource.cs b/src/libraries/Microsoft.Extensions.Logging.EventSource/src/LoggingEventSource.cs index 9ea52e603c222b..177c674f3b34d2 100644 --- a/src/libraries/Microsoft.Extensions.Logging.EventSource/src/LoggingEventSource.cs +++ b/src/libraries/Microsoft.Extensions.Logging.EventSource/src/LoggingEventSource.cs @@ -82,8 +82,10 @@ namespace Microsoft.Extensions.Logging.EventSource /// } /// /// +#pragma warning disable ESGEN001 // EventSource class is not partial. It's blocked by https://github.com/dotnet/runtime/issues/121205 [EventSource(Name = "Microsoft-Extensions-Logging")] public sealed class LoggingEventSource : System.Diagnostics.Tracing.EventSource +#pragma warning restore ESGEN001 { /// /// Defines the different ways data can be formatted in an event. @@ -126,6 +128,7 @@ public static class Keywords private static readonly char[] s_semicolon = new[] { ';' }; private static readonly char[] s_colon = new[] { ':' }; + // This event source uses IEnumerable as an event parameter type which is only supported by EtwSelfDescribingEventFormat. private LoggingEventSource() : base(EventSourceSettings.EtwSelfDescribingEventFormat) { } diff --git a/src/libraries/NetCoreAppLibrary.props b/src/libraries/NetCoreAppLibrary.props index 2a03638b2cfd9f..3cbcc8e90c539d 100644 --- a/src/libraries/NetCoreAppLibrary.props +++ b/src/libraries/NetCoreAppLibrary.props @@ -181,6 +181,7 @@ ComInterfaceGenerator; + EventSourceGenerator; LibraryImportGenerator; JSImportGenerator; Microsoft.Interop.SourceGeneration; diff --git a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/CDSCollectionETWBCLProvider.cs b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/CDSCollectionETWBCLProvider.cs index 1eff615ae941b6..8cf3cab2f42106 100644 --- a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/CDSCollectionETWBCLProvider.cs +++ b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/CDSCollectionETWBCLProvider.cs @@ -19,15 +19,12 @@ namespace System.Collections.Concurrent Name = "System.Collections.Concurrent.ConcurrentCollectionsEventSource", Guid = "35167F8E-49B2-4b96-AB86-435B59336B5E" )] - internal sealed class CDSCollectionETWBCLProvider : EventSource + internal sealed partial class CDSCollectionETWBCLProvider : EventSource { /// /// Defines the singleton instance for the collection ETW provider. - /// The collection provider GUID is {35167F8E-49B2-4b96-AB86-435B59336B5E}. /// public static readonly CDSCollectionETWBCLProvider Log = new CDSCollectionETWBCLProvider(); - /// Prevent external instantiation. All logging should go through the Log instance. - private CDSCollectionETWBCLProvider() { } /// Enabled for all keywords. private const EventKeywords ALL_KEYWORDS = (EventKeywords)(-1); diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/DataCommonEventSource.cs b/src/libraries/System.Data.Common/src/System/Data/Common/DataCommonEventSource.cs index 0144c53cf75220..3d32b06bb666ce 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/DataCommonEventSource.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/DataCommonEventSource.cs @@ -7,7 +7,7 @@ namespace System.Data { [EventSource(Name = "System.Data.DataCommonEventSource")] - internal sealed class DataCommonEventSource : EventSource + internal sealed partial class DataCommonEventSource : EventSource { internal static readonly DataCommonEventSource Log = new DataCommonEventSource(); private static long s_nextScopeId; diff --git a/src/libraries/System.Data.OleDb/src/System/Data/Common/DataCommonEventSource.cs b/src/libraries/System.Data.OleDb/src/System/Data/Common/DataCommonEventSource.cs index 5fc0234b3c9b98..5dd2d1a511aced 100644 --- a/src/libraries/System.Data.OleDb/src/System/Data/Common/DataCommonEventSource.cs +++ b/src/libraries/System.Data.OleDb/src/System/Data/Common/DataCommonEventSource.cs @@ -7,7 +7,7 @@ namespace System.Data { [EventSource(Name = "System.Data.DataCommonEventSource")] - internal sealed class DataCommonEventSource : EventSource + internal sealed partial class DataCommonEventSource : EventSource { internal static readonly DataCommonEventSource Log = new DataCommonEventSource(); private const int TraceEventId = 1; diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs index 431fc96b534e6a..fa26bfa9069080 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs @@ -159,8 +159,10 @@ namespace System.Diagnostics /// /// See the DiagnosticSourceEventSourceBridgeTest.cs for more explicit examples of using this bridge. /// +#pragma warning disable ESGEN001 // EventSource class is not partial. It's blocked by https://github.com/dotnet/runtime/issues/121205 [EventSource(Name = DiagnosticSourceEventSourceName)] internal sealed class DiagnosticSourceEventSource : EventSource +#pragma warning restore ESGEN001 { private const string DiagnosticSourceEventSourceName = "Microsoft-Diagnostics-DiagnosticSource"; @@ -404,10 +406,8 @@ protected override void OnEventCommand(EventCommandEventArgs command) } #region private - private DiagnosticSourceEventSource() - // This constructor uses EventSourceSettings which is only available on V4.6 and above - // Use the EventSourceSettings to turn on support for complex types, if available (v4.6 and above). - : base(DiagnosticSourceEventSourceName, EventSourceSettings.EtwSelfDescribingEventFormat) + // This event source uses IEnumerable as an event parameter type which is only supported by EtwSelfDescribingEventFormat. + private DiagnosticSourceEventSource() : base(DiagnosticSourceEventSourceName, EventSourceSettings.EtwSelfDescribingEventFormat) { } diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/MetricsEventSource.cs b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/MetricsEventSource.cs index 9656e8303c186b..6e32ccb5dab21d 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/MetricsEventSource.cs +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/MetricsEventSource.cs @@ -48,11 +48,9 @@ namespace System.Diagnostics.Metrics /// not counting the special zero bucket. The default value is 160. /// o reportDeltas - If true, the histogram will report deltas instead of whole accumulated values. The default value is false. /// - [EventSource(Name = MetricsEventSourceName)] - internal sealed class MetricsEventSource : EventSource + [EventSource(Name = "System.Diagnostics.Metrics")] + internal sealed partial class MetricsEventSource : EventSource { - private const string MetricsEventSourceName = "System.Diagnostics.Metrics"; - public static readonly MetricsEventSource Log = new(); // Although this API isn't public, it is invoked via reflection from System.Private.CoreLib and needs the same back-compat @@ -98,11 +96,6 @@ private CommandHandler Handler } } - private MetricsEventSource() - : base(MetricsEventSourceName, EventSourceSettings.EtwManifestEventFormat) - { - } - /// /// Used to send ad-hoc diagnostics to humans. /// diff --git a/src/libraries/System.Diagnostics.Tracing/ref/System.Diagnostics.Tracing.cs b/src/libraries/System.Diagnostics.Tracing/ref/System.Diagnostics.Tracing.cs index 30f85c26f85250..3938e9fc768713 100644 --- a/src/libraries/System.Diagnostics.Tracing/ref/System.Diagnostics.Tracing.cs +++ b/src/libraries/System.Diagnostics.Tracing/ref/System.Diagnostics.Tracing.cs @@ -155,6 +155,8 @@ protected EventSource(System.Diagnostics.Tracing.EventSourceSettings settings, p public EventSource(string eventSourceName) { } public EventSource(string eventSourceName, System.Diagnostics.Tracing.EventSourceSettings config) { } public EventSource(string eventSourceName, System.Diagnostics.Tracing.EventSourceSettings config, params string[]? traits) { } + public EventSource(string eventSourceName, System.Guid eventSourceGuid) { } + public EventSource(string eventSourceName, System.Guid eventSourceGuid, System.Diagnostics.Tracing.EventSourceSettings settings, params string[]? traits) { } public System.Exception? ConstructionException { get { throw null; } } public static System.Guid CurrentThreadActivityId { get { throw null; } } public System.Guid Guid { get { throw null; } } diff --git a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Utils/PLINQETWProvider.cs b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Utils/PLINQETWProvider.cs index 590dbce5a518cc..6421694b91a68b 100644 --- a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Utils/PLINQETWProvider.cs +++ b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Utils/PLINQETWProvider.cs @@ -22,15 +22,12 @@ namespace System.Linq.Parallel [EventSource( Name = "System.Linq.Parallel.PlinqEventSource", Guid = "159eeeec-4a14-4418-a8fe-faabcd987887")] - internal sealed class PlinqEtwProvider : EventSource + internal sealed partial class PlinqEtwProvider : EventSource { /// /// Defines the singleton instance for the PLINQ ETW provider. - /// The PLINQ Event provider GUID is {159eeeec-4a14-4418-a8fe-faabcd987887}. /// internal static readonly PlinqEtwProvider Log = new PlinqEtwProvider(); - /// Prevent external instantiation. All logging should go through the Log instance. - private PlinqEtwProvider() { } /// Cached id for the default scheduler. /// If PLINQ ever supports other schedulers, that information will need to be passed into the query events. diff --git a/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/NetEventSource.WinHttpHandler.cs b/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/NetEventSource.WinHttpHandler.cs index c3fc2335d362e4..d6a6adb8143708 100644 --- a/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/NetEventSource.WinHttpHandler.cs +++ b/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/NetEventSource.WinHttpHandler.cs @@ -5,11 +5,8 @@ namespace System.Net { - [EventSource(Name = NetEventSourceName)] + [EventSource(Name = "Private.InternalDiagnostics.System.Net.Http.WinHttpHandler")] internal sealed partial class NetEventSource { - private const string NetEventSourceName = "Private.InternalDiagnostics.System.Net.Http.WinHttpHandler"; - - public NetEventSource() : base(NetEventSourceName, EventSourceSettings.EtwManifestEventFormat) { } } } diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/HttpTelemetry.cs b/src/libraries/System.Net.Http/src/System/Net/Http/HttpTelemetry.cs index 1c7a6ce5f36b86..f06fb5c0314379 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/HttpTelemetry.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/HttpTelemetry.cs @@ -9,16 +9,9 @@ namespace System.Net.Http { - [EventSource(Name = HttpTelemetryName)] + [EventSource(Name = "System.Net.Http")] internal sealed partial class HttpTelemetry : EventSource { - private const string HttpTelemetryName = "System.Net.Http"; - - public HttpTelemetry() - : base(HttpTelemetryName, EventSourceSettings.EtwManifestEventFormat) - { - } - public static readonly HttpTelemetry Log = new HttpTelemetry(); public static class Keywords diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/NetEventSource.Http.cs b/src/libraries/System.Net.Http/src/System/Net/Http/NetEventSource.Http.cs index d3ba13ff485e2a..95c5af48e6c12a 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/NetEventSource.Http.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/NetEventSource.Http.cs @@ -7,13 +7,9 @@ namespace System.Net { - [EventSource(Name = NetEventSourceName)] + [EventSource(Name = "Private.InternalDiagnostics.System.Net.Http")] internal sealed partial class NetEventSource { - private const string NetEventSourceName = "Private.InternalDiagnostics.System.Net.Http"; - - public NetEventSource() : base(NetEventSourceName, EventSourceSettings.EtwManifestEventFormat) { } - private const int UriBaseAddressId = NextAvailableEventId; private const int ContentNullId = UriBaseAddressId + 1; private const int HeadersInvalidValueId = ContentNullId + 1; diff --git a/src/libraries/System.Net.HttpListener/src/System/Net/NetEventSource.HttpListener.cs b/src/libraries/System.Net.HttpListener/src/System/Net/NetEventSource.HttpListener.cs index a7b68f1952b748..3ef05bd677c08a 100644 --- a/src/libraries/System.Net.HttpListener/src/System/Net/NetEventSource.HttpListener.cs +++ b/src/libraries/System.Net.HttpListener/src/System/Net/NetEventSource.HttpListener.cs @@ -5,11 +5,8 @@ namespace System.Net { - [EventSource(Name = NetEventSourceName)] + [EventSource(Name = "Private.InternalDiagnostics.System.Net.HttpListener")] internal sealed partial class NetEventSource { - private const string NetEventSourceName = "Private.InternalDiagnostics.System.Net.HttpListener"; - - public NetEventSource() : base(NetEventSourceName, EventSourceSettings.EtwManifestEventFormat) { } } } diff --git a/src/libraries/System.Net.Mail/src/System/Net/Mail/NetEventSource.Mail.cs b/src/libraries/System.Net.Mail/src/System/Net/Mail/NetEventSource.Mail.cs index fabf71247ec6c5..d7589a6846c717 100644 --- a/src/libraries/System.Net.Mail/src/System/Net/Mail/NetEventSource.Mail.cs +++ b/src/libraries/System.Net.Mail/src/System/Net/Mail/NetEventSource.Mail.cs @@ -7,11 +7,8 @@ namespace System.Net { - [EventSource(Name = NetEventSourceName)] + [EventSource(Name = "Private.InternalDiagnostics.System.Net.Mail")] internal sealed partial class NetEventSource { - private const string NetEventSourceName = "Private.InternalDiagnostics.System.Net.Mail"; - - public NetEventSource() : base(NetEventSourceName, EventSourceSettings.EtwManifestEventFormat) { } } } diff --git a/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionTelemetry.cs b/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionTelemetry.cs index e7b4266701ad8a..59c2b47cc00a3a 100644 --- a/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionTelemetry.cs +++ b/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionTelemetry.cs @@ -9,16 +9,9 @@ namespace System.Net { - [EventSource(Name = NameResolutionTelemetryName)] - internal sealed class NameResolutionTelemetry : EventSource + [EventSource(Name = "System.Net.NameResolution")] + internal sealed partial class NameResolutionTelemetry : EventSource { - private const string NameResolutionTelemetryName = "System.Net.NameResolution"; - - public NameResolutionTelemetry() - : base(NameResolutionTelemetryName, EventSourceSettings.EtwManifestEventFormat) - { - } - public static readonly NameResolutionTelemetry Log = new NameResolutionTelemetry(); private const int ResolutionStartEventId = 1; diff --git a/src/libraries/System.Net.NameResolution/src/System/Net/NetEventSource.NameResolution.cs b/src/libraries/System.Net.NameResolution/src/System/Net/NetEventSource.NameResolution.cs index e4ef4f752ab1c6..89ec14ab2edd6e 100644 --- a/src/libraries/System.Net.NameResolution/src/System/Net/NetEventSource.NameResolution.cs +++ b/src/libraries/System.Net.NameResolution/src/System/Net/NetEventSource.NameResolution.cs @@ -5,11 +5,8 @@ namespace System.Net { - [EventSource(Name = NetEventSourceName)] + [EventSource(Name = "Private.InternalDiagnostics.System.Net.NameResolution")] internal sealed partial class NetEventSource { - private const string NetEventSourceName = "Private.InternalDiagnostics.System.Net.NameResolution"; - - public NetEventSource() : base(NetEventSourceName, EventSourceSettings.EtwManifestEventFormat) { } } } diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetEventSource.NetworkInformation.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetEventSource.NetworkInformation.cs index 74c8ec1e8228bd..d6293b9101ec4d 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetEventSource.NetworkInformation.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetEventSource.NetworkInformation.cs @@ -7,13 +7,9 @@ namespace System.Net { - [EventSource(Name = NetEventSourceName)] - internal sealed class NetEventSource : EventSource + [EventSource(Name = "Private.InternalDiagnostics.System.Net.NetworkInformation")] + internal sealed partial class NetEventSource : EventSource { - private const string NetEventSourceName = "Private.InternalDiagnostics.System.Net.NetworkInformation"; - - public NetEventSource() : base(NetEventSourceName, EventSourceSettings.EtwManifestEventFormat) { } - public static readonly NetEventSource Log = new NetEventSource(); private const int ErrorEventId = 2; diff --git a/src/libraries/System.Net.Primitives/src/System/Net/NetEventSource.Primitives.cs b/src/libraries/System.Net.Primitives/src/System/Net/NetEventSource.Primitives.cs index 58c50d26c6ef16..271827788686da 100644 --- a/src/libraries/System.Net.Primitives/src/System/Net/NetEventSource.Primitives.cs +++ b/src/libraries/System.Net.Primitives/src/System/Net/NetEventSource.Primitives.cs @@ -5,11 +5,8 @@ namespace System.Net { - [EventSource(Name = NetEventSourceName)] + [EventSource(Name = "Private.InternalDiagnostics.System.Net.Primitives")] internal sealed partial class NetEventSource { - private const string NetEventSourceName = "Private.InternalDiagnostics.System.Net.Primitives"; - - public NetEventSource() : base(NetEventSourceName, EventSourceSettings.EtwManifestEventFormat) { } } } diff --git a/src/libraries/System.Net.Quic/src/System/Net/Quic/NetEventSource.Quic.cs b/src/libraries/System.Net.Quic/src/System/Net/Quic/NetEventSource.Quic.cs index 7e1ea926160686..37dbeab080837c 100644 --- a/src/libraries/System.Net.Quic/src/System/Net/Quic/NetEventSource.Quic.cs +++ b/src/libraries/System.Net.Quic/src/System/Net/Quic/NetEventSource.Quic.cs @@ -6,13 +6,9 @@ namespace System.Net { - [EventSource(Name = NetEventSourceName)] + [EventSource(Name = "Private.InternalDiagnostics.System.Net.Quic")] internal sealed partial class NetEventSource { - private const string NetEventSourceName = "Private.InternalDiagnostics.System.Net.Quic"; - - public NetEventSource() : base(NetEventSourceName, EventSourceSettings.EtwManifestEventFormat) { } - static partial void AdditionalCustomizedToString(object value, ref string? result) { if (value is MsQuicSafeHandle safeHandle) diff --git a/src/libraries/System.Net.Requests/src/System/Net/NetEventSource.Requests.cs b/src/libraries/System.Net.Requests/src/System/Net/NetEventSource.Requests.cs index 070684e7b45b61..1d1e4e3a23bbfc 100644 --- a/src/libraries/System.Net.Requests/src/System/Net/NetEventSource.Requests.cs +++ b/src/libraries/System.Net.Requests/src/System/Net/NetEventSource.Requests.cs @@ -5,11 +5,8 @@ namespace System.Net { - [EventSource(Name = NetEventSourceName)] + [EventSource(Name = "Private.InternalDiagnostics.System.Net.Requests")] internal sealed partial class NetEventSource { - private const string NetEventSourceName = "Private.InternalDiagnostics.System.Net.Requests"; - - public NetEventSource() : base(NetEventSourceName, EventSourceSettings.EtwManifestEventFormat) { } } } diff --git a/src/libraries/System.Net.Security/src/System/Net/Security/NetEventSource.Security.cs b/src/libraries/System.Net.Security/src/System/Net/Security/NetEventSource.Security.cs index 5835dec28d18c7..5ca0be27a35723 100644 --- a/src/libraries/System.Net.Security/src/System/Net/Security/NetEventSource.Security.cs +++ b/src/libraries/System.Net.Security/src/System/Net/Security/NetEventSource.Security.cs @@ -11,13 +11,9 @@ namespace System.Net { - [EventSource(Name = NetEventSourceName)] + [EventSource(Name = "Private.InternalDiagnostics.System.Net.Security")] internal sealed partial class NetEventSource { - private const string NetEventSourceName = "Private.InternalDiagnostics.System.Net.Security"; - - public NetEventSource() : base(NetEventSourceName, EventSourceSettings.EtwManifestEventFormat) { } - #if WINDOWS // More events are defined in NetEventSource.Security.Windows.cs private const int LocatingPrivateKeyId = OperationReturnedSomethingId + 1; diff --git a/src/libraries/System.Net.Security/src/System/Net/Security/NetSecurityTelemetry.cs b/src/libraries/System.Net.Security/src/System/Net/Security/NetSecurityTelemetry.cs index 2be354f4a71ce1..ac71e2127e43d5 100644 --- a/src/libraries/System.Net.Security/src/System/Net/Security/NetSecurityTelemetry.cs +++ b/src/libraries/System.Net.Security/src/System/Net/Security/NetSecurityTelemetry.cs @@ -9,16 +9,9 @@ namespace System.Net.Security { - [EventSource(Name = NetSecurityTelemetryName)] - internal sealed class NetSecurityTelemetry : EventSource + [EventSource(Name = "System.Net.Security")] + internal sealed partial class NetSecurityTelemetry : EventSource { - private const string NetSecurityTelemetryName = "System.Net.Security"; - - public NetSecurityTelemetry() - : base(NetSecurityTelemetryName, EventSourceSettings.EtwManifestEventFormat) - { - } - private const string ActivitySourceName = "Experimental.System.Net.Security"; private const string ActivityName = ActivitySourceName + ".TlsHandshake"; diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/NetEventSource.Sockets.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/NetEventSource.Sockets.cs index 99669d885af960..ed5460ffcb7c94 100644 --- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/NetEventSource.Sockets.cs +++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/NetEventSource.Sockets.cs @@ -7,13 +7,9 @@ namespace System.Net { - [EventSource(Name = NetEventSourceName)] + [EventSource(Name = "Private.InternalDiagnostics.System.Net.Sockets")] internal sealed partial class NetEventSource { - private const string NetEventSourceName = "Private.InternalDiagnostics.System.Net.Sockets"; - - public NetEventSource() : base(NetEventSourceName, EventSourceSettings.EtwManifestEventFormat) { } - private const int AcceptedId = NextAvailableEventId; private const int ConnectedId = AcceptedId + 1; private const int ConnectedAsyncDnsId = ConnectedId + 1; diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketsTelemetry.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketsTelemetry.cs index 3507638bc2ca20..1171961a204351 100644 --- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketsTelemetry.cs +++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketsTelemetry.cs @@ -7,16 +7,9 @@ namespace System.Net.Sockets { - [EventSource(Name = SocketsTelemetryName)] - internal sealed class SocketsTelemetry : EventSource + [EventSource(Name = "System.Net.Sockets")] + internal sealed partial class SocketsTelemetry : EventSource { - private const string SocketsTelemetryName = "System.Net.Sockets"; - - public SocketsTelemetry() - : base(SocketsTelemetryName, EventSourceSettings.EtwManifestEventFormat) - { - } - private const string ActivitySourceName = "Experimental.System.Net.Sockets"; private const string ConnectActivityName = ActivitySourceName + ".Connect"; private static readonly ActivitySource s_connectActivitySource = new ActivitySource(ActivitySourceName); diff --git a/src/libraries/System.Net.WebSockets/src/System/Net/WebSockets/NetEventSource.WebSockets.cs b/src/libraries/System.Net.WebSockets/src/System/Net/WebSockets/NetEventSource.WebSockets.cs index 4f8ae05d2fbe20..fceeadd862d3c6 100644 --- a/src/libraries/System.Net.WebSockets/src/System/Net/WebSockets/NetEventSource.WebSockets.cs +++ b/src/libraries/System.Net.WebSockets/src/System/Net/WebSockets/NetEventSource.WebSockets.cs @@ -8,13 +8,9 @@ namespace System.Net { - [EventSource(Name = NetEventSourceName)] + [EventSource(Name = "Private.InternalDiagnostics.System.Net.WebSockets")] internal sealed partial class NetEventSource { - private const string NetEventSourceName = "Private.InternalDiagnostics.System.Net.WebSockets"; - - public NetEventSource() : base(NetEventSourceName, EventSourceSettings.EtwManifestEventFormat) { } - // NOTE // - The 'Start' and 'Stop' suffixes on the following event names have special meaning in EventSource. They // enable creating 'activities'. diff --git a/src/libraries/System.Private.CoreLib/gen/EventSourceGenerator.Emitter.cs b/src/libraries/System.Private.CoreLib/gen/EventSourceGenerator.Emitter.cs index 2dcedb1b435ce8..a0e424342fd381 100644 --- a/src/libraries/System.Private.CoreLib/gen/EventSourceGenerator.Emitter.cs +++ b/src/libraries/System.Private.CoreLib/gen/EventSourceGenerator.Emitter.cs @@ -17,6 +17,12 @@ public partial class EventSourceGenerator private static void EmitSourceFile(SourceProductionContext context, EventSourceClass ec) { + if (ec.Diagnostic != null) + { + context.ReportDiagnostic(ec.Diagnostic); + return; + } + StringBuilder sb = new StringBuilder(1024); sb.AppendLine(@"// "); @@ -42,7 +48,10 @@ partial class {ec.ClassName} {{"); GenerateConstructor(ec, sb); - GenerateProviderMetadata(ec.SourceName, sb); + if (ec.HasProviderMetadataProperty) + { + GenerateProviderMetadata(ec.SourceName, sb); + } sb.AppendLine($@" }}"); @@ -57,13 +66,13 @@ partial class {ec.ClassName} private static void GenerateConstructor(EventSourceClass ec, StringBuilder sb) { sb.AppendLine($@" - private {ec.ClassName}() : base(new Guid({ec.Guid.ToString("x").Replace("{", "").Replace("}", "")}), ""{ec.SourceName}"") {{ }}"); + private {ec.ClassName}() : base(""{ec.SourceName}"", new Guid({ec.Guid.ToString("x").Replace("{", "").Replace("}", "")})) {{ }}"); } private static void GenerateProviderMetadata(string sourceName, StringBuilder sb) { sb.Append(@" - private protected override ReadOnlySpan ProviderMetadata => new byte[] { "); + private protected override ReadOnlySpan ProviderMetadata => ["); byte[] metadataBytes = MetadataForString(sourceName); foreach (byte b in metadataBytes) @@ -71,7 +80,7 @@ private static void GenerateProviderMetadata(string sourceName, StringBuilder sb sb.Append($"0x{b:x}, "); } - sb.AppendLine(@"};"); + sb.AppendLine(@"];"); } // From System.Private.CoreLib diff --git a/src/libraries/System.Private.CoreLib/gen/EventSourceGenerator.Parser.cs b/src/libraries/System.Private.CoreLib/gen/EventSourceGenerator.Parser.cs index fa2e1a2fc8598e..85f884958e642b 100644 --- a/src/libraries/System.Private.CoreLib/gen/EventSourceGenerator.Parser.cs +++ b/src/libraries/System.Private.CoreLib/gen/EventSourceGenerator.Parser.cs @@ -4,10 +4,12 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; +using System.IO; using System.Security.Cryptography; using System.Text; using System.Threading; using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; namespace Generators @@ -40,6 +42,62 @@ public partial class EventSourceGenerator continue; } + bool isPartial = false; + foreach (var modifier in classDef.Modifiers) + { + if (modifier.IsKind(SyntaxKind.PartialKeyword)) + { + isPartial = true; + break; + } + } + + if (!isPartial) + { + var diagnostic = Diagnostic.Create( + new DiagnosticDescriptor( + "ESGEN001", + "EventSource class is not partial", + "EventSource class '{0}' is not partial. EventSource classes must be declared as partial to take advantage of EventSourceGenerator.", + nameof(EventSourceGenerator), + DiagnosticSeverity.Warning, + isEnabledByDefault: true), + classDef.GetLocation(), + classDef.Identifier.ValueText); + return new EventSourceClass(diagnostic, null, null, null, default, false); + } + + foreach (MemberDeclarationSyntax member in classDef.Members) + { + if (member is ConstructorDeclarationSyntax ctor) + { + bool isStatic = false; + foreach (SyntaxToken ctorModifier in ctor.Modifiers) + { + if (ctorModifier.IsKind(SyntaxKind.StaticKeyword)) + { + isStatic = true; + break; + } + } + + if (!isStatic) + { + var diagnostic = Diagnostic.Create( + new DiagnosticDescriptor( + "ESGEN002", + "EventSource class contains explicit constructor", + "EventSource class '{0}' contains an explicit constructor. EventSource classes must not declare constructors to take advantage of EventSourceGenerator.", + nameof(EventSourceGenerator), + DiagnosticSeverity.Warning, + isEnabledByDefault: true), + classDef.GetLocation(), + classDef.Identifier.ValueText); + return new EventSourceClass(diagnostic, null, null, null, default, false); + } + } + } + nspace ??= ConstructNamespace(ns); string className = classDef.Identifier.ValueText; @@ -68,14 +126,24 @@ public partial class EventSourceGenerator result = GenerateGuidFromName(name.ToUpperInvariant()); } - eventSourceClass = new EventSourceClass(nspace, className, name, result); + bool hasProviderMetadataProperty = false; + foreach (MemberDeclarationSyntax member in classDef.Members) + { + if (member is PropertyDeclarationSyntax prop && prop.Identifier.Text == "ProviderMetadata") + { + hasProviderMetadataProperty = true; + break; + } + } + + eventSourceClass = new EventSourceClass(null, nspace, className, name, result, hasProviderMetadataProperty); continue; } return eventSourceClass; } - private static string? ConstructNamespace(NamespaceDeclarationSyntax? ns) + private static string ConstructNamespace(NamespaceDeclarationSyntax? ns) { if (ns is null) return string.Empty; diff --git a/src/libraries/System.Private.CoreLib/gen/EventSourceGenerator.cs b/src/libraries/System.Private.CoreLib/gen/EventSourceGenerator.cs index 90ea79020dda9f..8162be97142f5b 100644 --- a/src/libraries/System.Private.CoreLib/gen/EventSourceGenerator.cs +++ b/src/libraries/System.Private.CoreLib/gen/EventSourceGenerator.cs @@ -16,7 +16,6 @@ public partial class EventSourceGenerator : IIncrementalGenerator // Example input: // // [EventSource(Guid = "49592C0F-5A05-516D-AA4B-A64E02026C89", Name = "System.Runtime")] - // [EventSourceAutoGenerate] // internal sealed partial class RuntimeEventSource : EventSource // // Example generated output: @@ -27,7 +26,7 @@ public partial class EventSourceGenerator : IIncrementalGenerator // { // partial class RuntimeEventSource // { - // private RuntimeEventSource() : base(new Guid(0x49592c0f,0x5a05,0x516d,0xaa,0x4b,0xa6,0x4e,0x02,0x02,0x6c,0x89), "System.Runtime") { } + // private RuntimeEventSource() : base("System.Runtime", new Guid(0x49592c0f,0x5a05,0x516d,0xaa,0x4b,0xa6,0x4e,0x02,0x02,0x6c,0x89)) { } // // private protected override ReadOnlySpan ProviderMetadata => new byte[] { 0x11, 0x0, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x52, 0x75, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x0, }; // } @@ -35,11 +34,11 @@ public partial class EventSourceGenerator : IIncrementalGenerator public void Initialize(IncrementalGeneratorInitializationContext context) { - const string EventSourceAutoGenerateAttribute = "System.Diagnostics.Tracing.EventSourceAutoGenerateAttribute"; + const string EventSourceAttribute = "System.Diagnostics.Tracing.EventSourceAttribute"; IncrementalValuesProvider eventSourceClasses = context.SyntaxProvider.ForAttributeWithMetadataName( - EventSourceAutoGenerateAttribute, + EventSourceAttribute, (node, _) => node is ClassDeclarationSyntax, GetSemanticTargetForGeneration) .Where(x => x is not null); @@ -47,6 +46,12 @@ public void Initialize(IncrementalGeneratorInitializationContext context) context.RegisterSourceOutput(eventSourceClasses, EmitSourceFile); } - private sealed record EventSourceClass(string Namespace, string ClassName, string SourceName, Guid Guid); + private sealed record EventSourceClass( + Diagnostic Diagnostic, + string Namespace, + string ClassName, + string SourceName, + Guid Guid, + bool HasProviderMetadataProperty); } } diff --git a/src/libraries/System.Private.CoreLib/gen/EventSourceGenerator.csproj b/src/libraries/System.Private.CoreLib/gen/EventSourceGenerator.csproj new file mode 100644 index 00000000000000..11e72b22f18b6c --- /dev/null +++ b/src/libraries/System.Private.CoreLib/gen/EventSourceGenerator.csproj @@ -0,0 +1,22 @@ + + + netstandard2.0 + $(NoWarn);CS3001 + true + + + $(DefineConstants);STABILIZE_PACKAGE_VERSION + + + + + + + + + + + + + + diff --git a/src/libraries/System.Private.CoreLib/gen/System.Private.CoreLib.Generators.csproj b/src/libraries/System.Private.CoreLib/gen/System.Private.CoreLib.Generators.csproj index 79a254539cee71..f5aa981c3a3c76 100644 --- a/src/libraries/System.Private.CoreLib/gen/System.Private.CoreLib.Generators.csproj +++ b/src/libraries/System.Private.CoreLib/gen/System.Private.CoreLib.Generators.csproj @@ -10,9 +10,6 @@ - - - diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffers/ArrayPoolEventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Buffers/ArrayPoolEventSource.cs index b2855224fc12e4..8a0f9582864941 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Buffers/ArrayPoolEventSource.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Buffers/ArrayPoolEventSource.cs @@ -7,7 +7,6 @@ namespace System.Buffers { [EventSource(Guid = "0866B2B8-5CEF-5DB9-2612-0C0FFD814A44", Name = "System.Buffers.ArrayPoolEventSource")] - [EventSourceAutoGenerate] internal sealed partial class ArrayPoolEventSource : EventSource { private const string EventSourceSuppressMessage = "Parameters to this method are primitive and are trimmer safe"; @@ -36,10 +35,6 @@ internal enum BufferDroppedReason : int OverMaximumSize, } - // Parameterized constructor to block initialization and ensure the EventSourceGenerator is creating the default constructor - // as you can't make a constructor partial. - private ArrayPoolEventSource(int _) { } - /// /// Event for when a buffer is rented. This is invoked once for every successful call to Rent, /// regardless of whether a buffer is allocated or a buffer is taken from the pool. In a diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs index 50c72800319882..9407cc9426d617 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs @@ -177,12 +177,6 @@ namespace System.Diagnostics.Tracing { - [Conditional("NEEDED_FOR_SOURCE_GENERATOR_ONLY")] - [AttributeUsage(AttributeTargets.Class)] - internal sealed class EventSourceAutoGenerateAttribute : Attribute - { - } - /// /// This class is meant to be inherited by a user-defined event source in order to define a managed /// ETW provider. Please See DESIGN NOTES above for the internal architecture. @@ -1612,12 +1606,12 @@ private unsafe void WriteEventRaw( // FrameworkEventSource is on the startup path for the framework, so we have this internal overload that it can use // to prevent the working set hit from looking at the custom attributes on the type to get the Guid. - internal EventSource(Guid eventSourceGuid, string eventSourceName) - : this(eventSourceGuid, eventSourceName, EventSourceSettings.EtwManifestEventFormat) + public EventSource(string eventSourceName, Guid eventSourceGuid) + : this(eventSourceName, eventSourceGuid, EventSourceSettings.EtwManifestEventFormat) { } // Used by the internal FrameworkEventSource constructor and the TraceLogging-style event source constructor - internal EventSource(Guid eventSourceGuid, string eventSourceName, EventSourceSettings settings, string[]? traits = null) + public EventSource(string eventSourceName, Guid eventSourceGuid, EventSourceSettings settings, string[]? traits = null) { if (IsSupported) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/FrameworkEventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/FrameworkEventSource.cs index 264f4a6bc85576..20f76ff9b646fe 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/FrameworkEventSource.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/FrameworkEventSource.cs @@ -7,7 +7,6 @@ namespace System.Diagnostics.Tracing { [EventSource(Guid = "8E9F5090-2D75-4d03-8A81-E5AFBF85DAF1", Name = "System.Diagnostics.Eventing.FrameworkEventSource")] - [EventSourceAutoGenerate] internal sealed partial class FrameworkEventSource : EventSource { private const string EventSourceSuppressMessage = "Parameters to this method are primitive and are trimmer safe"; @@ -30,10 +29,6 @@ public static class Keywords public const EventTask ThreadTransfer = (EventTask)3; } - // Parameterized constructor to block initialization and ensure the EventSourceGenerator is creating the default constructor - // as you can't make a constructor partial. - private FrameworkEventSource(int _) { } - // optimized for common signatures (used by the ThreadTransferSend/Receive events) [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", Justification = EventSourceSuppressMessage)] diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/NativeRuntimeEventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/NativeRuntimeEventSource.cs index 092cd3af35d078..0f1b7817bc202d 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/NativeRuntimeEventSource.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/NativeRuntimeEventSource.cs @@ -23,7 +23,6 @@ namespace System.Diagnostics.Tracing /// for the native platform. /// [EventSource(Guid = "E13C0D23-CCBC-4E12-931B-D9CC2EEE27E4", Name = EventSourceName)] - [EventSourceAutoGenerate] internal sealed partial class NativeRuntimeEventSource : EventSource { internal const string EventSourceName = "Microsoft-Windows-DotNETRuntime"; @@ -34,10 +33,6 @@ internal sealed partial class NativeRuntimeEventSource : EventSource // pools would be in moderate use. private const ushort DefaultClrInstanceId = 0; - // Parameterized constructor to block initialization and ensure the EventSourceGenerator is creating the default constructor - // as you can't make a constructor partial. - private NativeRuntimeEventSource(int _) { } - #if FEATURE_PERFTRACING /// /// Dispatch a single event with the specified event ID and payload. diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/RuntimeEventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/RuntimeEventSource.cs index 30f62f7b4d5769..1ec6bfb52b6404 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/RuntimeEventSource.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/RuntimeEventSource.cs @@ -10,12 +10,9 @@ namespace System.Diagnostics.Tracing /// /// RuntimeEventSource is an EventSource that represents events emitted by the managed runtime. /// - [EventSource(Guid = "49592C0F-5A05-516D-AA4B-A64E02026C89", Name = EventSourceName)] - [EventSourceAutoGenerate] + [EventSource(Guid = "49592C0F-5A05-516D-AA4B-A64E02026C89", Name = "System.Runtime")] internal sealed partial class RuntimeEventSource : EventSource { - internal const string EventSourceName = "System.Runtime"; - public static class Keywords { public const EventKeywords AppContext = (EventKeywords)0x1; @@ -52,10 +49,6 @@ public static class Keywords private PollingCounter? _methodsJittedCounter; private IncrementingPollingCounter? _jitTimeCounter; - // Parameterized constructor to block initialization and ensure the EventSourceGenerator is creating the default constructor - // as you can't make a constructor partial. - private RuntimeEventSource(int _) { } - private enum EventId : int { AppContextSwitch = 1, diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs index 20c6c8516d9f40..e18a27209475cf 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs @@ -70,8 +70,8 @@ public EventSource( EventSourceSettings config, params string[]? traits) : this( - GenerateGuidFromName((eventSourceName ?? throw new ArgumentNullException(nameof(eventSourceName))).ToUpperInvariant()), eventSourceName, + GenerateGuidFromName((eventSourceName ?? throw new ArgumentNullException(nameof(eventSourceName))).ToUpperInvariant()), config, traits) { } diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TplEventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TplEventSource.cs index 16eee9081ceb96..5418d665ab43b1 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TplEventSource.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TplEventSource.cs @@ -12,7 +12,6 @@ namespace System.Threading.Tasks Name = "System.Threading.Tasks.TplEventSource", Guid = "2e5dba47-a3d2-4d16-8ee0-6671ffdcd7b5" )] - [EventSourceAutoGenerate] internal sealed partial class TplEventSource : EventSource { private const string EventSourceSuppressMessage = "Parameters to this method are primitive and are trimmer safe"; @@ -42,10 +41,6 @@ protected override void OnEventCommand(EventCommandEventArgs command) /// public static readonly TplEventSource Log = new TplEventSource(); - // Parameterized constructor to block initialization and ensure the EventSourceGenerator is creating the default constructor - // as you can't make a constructor partial. - private TplEventSource(int _) { } - /// Configured behavior of a task wait operation. public enum TaskWaitBehavior : int { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationEventSource.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationEventSource.cs index ca093164ff6094..b68ecb2b86f666 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationEventSource.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationEventSource.cs @@ -5,16 +5,9 @@ namespace System.Xml.Serialization { - [EventSource(Name = XmlSerializationEventSourceName)] - internal sealed class XmlSerializationEventSource : EventSource + [EventSource(Name = "System.Xml.Serialzation.XmlSerialization")] + internal sealed partial class XmlSerializationEventSource : EventSource { - private const string XmlSerializationEventSourceName = "System.Xml.Serialzation.XmlSerialization"; - - public XmlSerializationEventSource() - : base(XmlSerializationEventSourceName, EventSourceSettings.EtwManifestEventFormat) - { - } - internal static readonly XmlSerializationEventSource Log = new XmlSerializationEventSource(); [Event(EventIds.XmlSerializerExpired, Level = EventLevel.Informational)] diff --git a/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryFormatterEventSource.cs b/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryFormatterEventSource.cs index 70ebce0d4e004e..3fc9a9006b90f8 100644 --- a/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryFormatterEventSource.cs +++ b/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryFormatterEventSource.cs @@ -8,7 +8,7 @@ namespace System.Runtime.Serialization.Formatters.Binary { [EventSource( Name = "System.Runtime.Serialization.Formatters.Binary.BinaryFormatterEventSource")] - internal sealed class BinaryFormatterEventSource : EventSource + internal sealed partial class BinaryFormatterEventSource : EventSource { private const int EventId_SerializationStart = 10; private const int EventId_SerializationStop = 11; @@ -19,10 +19,6 @@ internal sealed class BinaryFormatterEventSource : EventSource public static readonly BinaryFormatterEventSource Log = new BinaryFormatterEventSource(); - private BinaryFormatterEventSource() - { - } - [Event(EventId_SerializationStart, Opcode = EventOpcode.Start, Keywords = Keywords.Serialization, Level = EventLevel.Informational, ActivityOptions = EventActivityOptions.Recursive)] public void SerializationStart() { diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/OpenSslX509ChainEventSource.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/OpenSslX509ChainEventSource.cs index 726b3486d939bf..3facb39ae1320c 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/OpenSslX509ChainEventSource.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/OpenSslX509ChainEventSource.cs @@ -7,16 +7,9 @@ namespace System.Security.Cryptography.X509Certificates { - [EventSource(Name = OpenSslX509ChainEventSourceName)] - internal sealed class OpenSslX509ChainEventSource : EventSource + [EventSource(Name = "System.Security.Cryptography.X509Certificates.X509Chain.OpenSsl")] + internal sealed partial class OpenSslX509ChainEventSource : EventSource { - private const string OpenSslX509ChainEventSourceName = "System.Security.Cryptography.X509Certificates.X509Chain.OpenSsl"; - - public OpenSslX509ChainEventSource() - : base(OpenSslX509ChainEventSourceName, EventSourceSettings.EtwManifestEventFormat) - { - } - internal static readonly OpenSslX509ChainEventSource Log = new OpenSslX509ChainEventSource(); private const int EventId_ChainStart = 1; diff --git a/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/DataflowEtwProvider.cs b/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/DataflowEtwProvider.cs index 2f17ecf0cc8441..39298b164bfbe1 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/DataflowEtwProvider.cs +++ b/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/DataflowEtwProvider.cs @@ -22,15 +22,12 @@ namespace System.Threading.Tasks.Dataflow.Internal [EventSource( Name = "System.Threading.Tasks.Dataflow.DataflowEventSource", Guid = "16F53577-E41D-43D4-B47E-C17025BF4025")] - internal sealed class DataflowEtwProvider : EventSource + internal sealed partial class DataflowEtwProvider : EventSource { /// /// Defines the singleton instance for the dataflow ETW provider. - /// The dataflow provider GUID is {16F53577-E41D-43D4-B47E-C17025BF4025}. /// internal static readonly DataflowEtwProvider Log = new DataflowEtwProvider(); - /// Prevent external instantiation. All logging should go through the Log instance. - private DataflowEtwProvider() { } /// Enabled for all keywords. private const EventKeywords ALL_KEYWORDS = (EventKeywords)(-1); diff --git a/src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/ParallelETWProvider.cs b/src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/ParallelETWProvider.cs index 3e92c6790bb58c..d3e735115c9f2b 100644 --- a/src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/ParallelETWProvider.cs +++ b/src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/ParallelETWProvider.cs @@ -18,7 +18,7 @@ namespace System.Threading.Tasks { /// Provides an event source for tracing TPL information. [EventSource(Name = "System.Threading.Tasks.Parallel.EventSource")] - internal sealed class ParallelEtwProvider : EventSource + internal sealed partial class ParallelEtwProvider : EventSource { private const string EventSourceSuppressMessage = "Parameters to this method are primitive and are trimmer safe"; /// @@ -26,9 +26,6 @@ internal sealed class ParallelEtwProvider : EventSource /// public static readonly ParallelEtwProvider Log = new ParallelEtwProvider(); - /// Prevent external instantiation. All logging should go through the Log instance. - private ParallelEtwProvider() { } - /// Type of a fork/join operation. public enum ForkJoinOperationType { diff --git a/src/libraries/System.Threading/src/System/Threading/CDSsyncETWBCLProvider.cs b/src/libraries/System.Threading/src/System/Threading/CDSsyncETWBCLProvider.cs index 64f46a74635bc4..e04feef4668fb0 100644 --- a/src/libraries/System.Threading/src/System/Threading/CDSsyncETWBCLProvider.cs +++ b/src/libraries/System.Threading/src/System/Threading/CDSsyncETWBCLProvider.cs @@ -25,15 +25,12 @@ namespace System.Threading Name = "System.Threading.SynchronizationEventSource", Guid = "EC631D38-466B-4290-9306-834971BA0217" )] - internal sealed class CdsSyncEtwBCLProvider : EventSource + internal sealed partial class CdsSyncEtwBCLProvider : EventSource { /// /// Defines the singleton instance for the CDS Sync ETW provider. - /// The CDS Sync Event provider GUID is {EC631D38-466B-4290-9306-834971BA0217}. /// public static readonly CdsSyncEtwBCLProvider Log = new CdsSyncEtwBCLProvider(); - /// Prevent external instantiation. All logging should go through the Log instance. - private CdsSyncEtwBCLProvider() { } /// Enabled for all keywords. private const EventKeywords ALL_KEYWORDS = (EventKeywords)(-1); diff --git a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionsEtwProvider.cs b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionsEtwProvider.cs index 39ab21b8049674..2b75b69b9acca0 100644 --- a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionsEtwProvider.cs +++ b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionsEtwProvider.cs @@ -74,18 +74,12 @@ internal enum TraceSourceType [EventSource( Name = "System.Transactions.TransactionsEventSource", Guid = "8ac2d80a-1f1a-431b-ace4-bff8824aef0b")] - internal sealed class TransactionsEtwProvider : EventSource + internal sealed partial class TransactionsEtwProvider : EventSource { /// /// Defines the singleton instance for the Transactions ETW provider. - /// The Transactions provider GUID is {8ac2d80a-1f1a-431b-ace4-bff8824aef0b}. /// - /// - - internal static readonly TransactionsEtwProvider Log = new TransactionsEtwProvider(); - /// Prevent external instantiation. All logging should go through the Log instance. - private TransactionsEtwProvider() { } /// Enabled for all keywords. private const EventKeywords ALL_KEYWORDS = (EventKeywords)(-1);