Skip to content

Commit 8304b03

Browse files
authored
Avoid custom attribute routine in NetEventSource (#120422)
* Avoid custom attribute routine in NetEventSource * add EventSourceSettings.EtwManifestEventFormat * Apply Miha's FB * revert * More event sources * fix whitespace * use EtwManifestEventFormat * DiagnosticSourceEvent uses self-describing one
1 parent 3c9b03e commit 8304b03

File tree

20 files changed

+131
-29
lines changed

20 files changed

+131
-29
lines changed

src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,11 @@ namespace System.Diagnostics
159159
///
160160
/// See the DiagnosticSourceEventSourceBridgeTest.cs for more explicit examples of using this bridge.
161161
/// </summary>
162-
[EventSource(Name = "Microsoft-Diagnostics-DiagnosticSource")]
162+
[EventSource(Name = DiagnosticSourceEventSourceName)]
163163
internal sealed class DiagnosticSourceEventSource : EventSource
164164
{
165+
private const string DiagnosticSourceEventSourceName = "Microsoft-Diagnostics-DiagnosticSource";
166+
165167
public static readonly DiagnosticSourceEventSource Log = new DiagnosticSourceEventSource();
166168

167169
public static class Keywords
@@ -405,7 +407,7 @@ protected override void OnEventCommand(EventCommandEventArgs command)
405407
private DiagnosticSourceEventSource()
406408
// This constructor uses EventSourceSettings which is only available on V4.6 and above
407409
// Use the EventSourceSettings to turn on support for complex types, if available (v4.6 and above).
408-
: base(EventSourceSettings.EtwSelfDescribingEventFormat)
410+
: base(DiagnosticSourceEventSourceName, EventSourceSettings.EtwSelfDescribingEventFormat)
409411
{
410412
}
411413

src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/MetricsEventSource.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ namespace System.Diagnostics.Metrics
4848
/// not counting the special zero bucket. The default value is 160.
4949
/// o reportDeltas - If true, the histogram will report deltas instead of whole accumulated values. The default value is false.
5050
/// </summary>
51-
[EventSource(Name = "System.Diagnostics.Metrics")]
51+
[EventSource(Name = MetricsEventSourceName)]
5252
internal sealed class MetricsEventSource : EventSource
5353
{
54+
private const string MetricsEventSourceName = "System.Diagnostics.Metrics";
55+
5456
public static readonly MetricsEventSource Log = new();
5557

5658
// Although this API isn't public, it is invoked via reflection from System.Private.CoreLib and needs the same back-compat
@@ -96,7 +98,10 @@ private CommandHandler Handler
9698
}
9799
}
98100

99-
private MetricsEventSource() { }
101+
private MetricsEventSource()
102+
: base(MetricsEventSourceName, EventSourceSettings.EtwManifestEventFormat)
103+
{
104+
}
100105

101106
/// <summary>
102107
/// Used to send ad-hoc diagnostics to humans.

src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/NetEventSource.WinHttpHandler.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55

66
namespace System.Net
77
{
8-
[EventSource(Name = "Private.InternalDiagnostics.System.Net.Http.WinHttpHandler")]
9-
internal sealed partial class NetEventSource { }
8+
[EventSource(Name = NetEventSourceName)]
9+
internal sealed partial class NetEventSource
10+
{
11+
private const string NetEventSourceName = "Private.InternalDiagnostics.System.Net.Http.WinHttpHandler";
12+
13+
public NetEventSource() : base(NetEventSourceName, EventSourceSettings.EtwManifestEventFormat) { }
14+
}
1015
}

src/libraries/System.Net.Http/src/System/Net/Http/HttpTelemetry.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,16 @@
99

1010
namespace System.Net.Http
1111
{
12-
[EventSource(Name = "System.Net.Http")]
12+
[EventSource(Name = HttpTelemetryName)]
1313
internal sealed partial class HttpTelemetry : EventSource
1414
{
15+
private const string HttpTelemetryName = "System.Net.Http";
16+
17+
public HttpTelemetry()
18+
: base(HttpTelemetryName, EventSourceSettings.EtwManifestEventFormat)
19+
{
20+
}
21+
1522
public static readonly HttpTelemetry Log = new HttpTelemetry();
1623

1724
public static class Keywords

src/libraries/System.Net.Http/src/System/Net/Http/NetEventSource.Http.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77

88
namespace System.Net
99
{
10-
[EventSource(Name = "Private.InternalDiagnostics.System.Net.Http")]
10+
[EventSource(Name = NetEventSourceName)]
1111
internal sealed partial class NetEventSource
1212
{
13+
private const string NetEventSourceName = "Private.InternalDiagnostics.System.Net.Http";
14+
15+
public NetEventSource() : base(NetEventSourceName, EventSourceSettings.EtwManifestEventFormat) { }
16+
1317
private const int UriBaseAddressId = NextAvailableEventId;
1418
private const int ContentNullId = UriBaseAddressId + 1;
1519
private const int HeadersInvalidValueId = ContentNullId + 1;

src/libraries/System.Net.HttpListener/src/System/Net/NetEventSource.HttpListener.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55

66
namespace System.Net
77
{
8-
[EventSource(Name = "Private.InternalDiagnostics.System.Net.HttpListener")]
9-
internal sealed partial class NetEventSource { }
8+
[EventSource(Name = NetEventSourceName)]
9+
internal sealed partial class NetEventSource
10+
{
11+
private const string NetEventSourceName = "Private.InternalDiagnostics.System.Net.HttpListener";
12+
13+
public NetEventSource() : base(NetEventSourceName, EventSourceSettings.EtwManifestEventFormat) { }
14+
}
1015
}

src/libraries/System.Net.Mail/src/System/Net/Mail/NetEventSource.Mail.cs

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

88
namespace System.Net
99
{
10-
[EventSource(Name = "Private.InternalDiagnostics.System.Net.Mail")]
11-
internal sealed partial class NetEventSource { }
10+
[EventSource(Name = NetEventSourceName)]
11+
internal sealed partial class NetEventSource
12+
{
13+
private const string NetEventSourceName = "Private.InternalDiagnostics.System.Net.Mail";
14+
15+
public NetEventSource() : base(NetEventSourceName, EventSourceSettings.EtwManifestEventFormat) { }
16+
}
1217
}

src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionTelemetry.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,16 @@
99

1010
namespace System.Net
1111
{
12-
[EventSource(Name = "System.Net.NameResolution")]
12+
[EventSource(Name = NameResolutionTelemetryName)]
1313
internal sealed class NameResolutionTelemetry : EventSource
1414
{
15+
private const string NameResolutionTelemetryName = "System.Net.NameResolution";
16+
17+
public NameResolutionTelemetry()
18+
: base(NameResolutionTelemetryName, EventSourceSettings.EtwManifestEventFormat)
19+
{
20+
}
21+
1522
public static readonly NameResolutionTelemetry Log = new NameResolutionTelemetry();
1623

1724
private const int ResolutionStartEventId = 1;

src/libraries/System.Net.NameResolution/src/System/Net/NetEventSource.NameResolution.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55

66
namespace System.Net
77
{
8-
[EventSource(Name = "Private.InternalDiagnostics.System.Net.NameResolution")]
9-
internal sealed partial class NetEventSource { }
8+
[EventSource(Name = NetEventSourceName)]
9+
internal sealed partial class NetEventSource
10+
{
11+
private const string NetEventSourceName = "Private.InternalDiagnostics.System.Net.NameResolution";
12+
13+
public NetEventSource() : base(NetEventSourceName, EventSourceSettings.EtwManifestEventFormat) { }
14+
}
1015
}

src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetEventSource.NetworkInformation.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77

88
namespace System.Net
99
{
10-
[EventSource(Name = "Private.InternalDiagnostics.System.Net.NetworkInformation")]
10+
[EventSource(Name = NetEventSourceName)]
1111
internal sealed class NetEventSource : EventSource
1212
{
13+
private const string NetEventSourceName = "Private.InternalDiagnostics.System.Net.NetworkInformation";
14+
15+
public NetEventSource() : base(NetEventSourceName, EventSourceSettings.EtwManifestEventFormat) { }
16+
1317
public static readonly NetEventSource Log = new NetEventSource();
1418

1519
private const int ErrorEventId = 2;

0 commit comments

Comments
 (0)