55using System . Diagnostics ;
66using System . Text ;
77using System . Runtime . InteropServices ;
8+ using System . Runtime . Versioning ;
89
910using Contract = System . Diagnostics . Contracts . Contract ;
1011
@@ -15,6 +16,9 @@ namespace System.Diagnostics.Tracing
1516
1617 internal class XplatEventLogger : EventListener
1718 {
19+ private static Lazy < string > eventSourceNameFilter = new Lazy < string > ( ( ) => CompatibilitySwitch . GetValueInternal ( "EventSourceFilter" ) ) ;
20+ private static Lazy < string > eventSourceEventFilter = new Lazy < string > ( ( ) => CompatibilitySwitch . GetValueInternal ( "EventNameFilter" ) ) ;
21+
1822 public XplatEventLogger ( ) { }
1923
2024 private static bool initializedPersistentListener = false ;
@@ -122,12 +126,20 @@ private static string Serialize(ReadOnlyCollection<string> payloadName, ReadOnly
122126
123127 internal protected override void OnEventSourceCreated ( EventSource eventSource )
124128 {
125- EnableEvents ( eventSource , EventLevel . LogAlways , EventKeywords . All , null ) ;
129+ string eventSourceFilter = eventSourceNameFilter . Value ;
130+ if ( String . IsNullOrEmpty ( eventSourceFilter ) || ( eventSource . Name . IndexOf ( eventSourceFilter , StringComparison . OrdinalIgnoreCase ) >= 0 ) )
131+ {
132+ EnableEvents ( eventSource , EventLevel . LogAlways , EventKeywords . All , null ) ;
133+ }
126134 }
127135
128136 internal protected override void OnEventWritten ( EventWrittenEventArgs eventData )
129137 {
130- LogOnEventWritten ( eventData ) ;
138+ string eventFilter = eventSourceEventFilter . Value ;
139+ if ( String . IsNullOrEmpty ( eventFilter ) || ( eventData . EventName . IndexOf ( eventFilter , StringComparison . OrdinalIgnoreCase ) >= 0 ) )
140+ {
141+ LogOnEventWritten ( eventData ) ;
142+ }
131143 }
132144
133145 [ System . Security . SecuritySafeCritical ]
0 commit comments