From 75918f0a9822948f7d3a47011195b8d065682981 Mon Sep 17 00:00:00 2001 From: David Mason Date: Tue, 31 May 2016 15:07:09 -0700 Subject: [PATCH] Add filtering logic to XplatEventLogger --- src/inc/clrconfigvalues.h | 2 ++ .../src/System/Diagnostics/Eventing/XplatEventLogger.cs | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/inc/clrconfigvalues.h b/src/inc/clrconfigvalues.h index 98c5aa5..a673f36 100644 --- a/src/inc/clrconfigvalues.h +++ b/src/inc/clrconfigvalues.h @@ -1027,6 +1027,8 @@ RETAIL_CONFIG_DWORD_INFO(EXTERNAL_ReadyToRun, W("ReadyToRun"), 0, "Enable/disabl #if defined(FEATURE_EVENT_TRACE) || defined(FEATURE_EVENTSOURCE_XPLAT) RETAIL_CONFIG_DWORD_INFO(EXTERNAL_EnableEventLog, W("EnableEventLog"), 0, "Enable/disable use of EnableEventLogging mechanism ") // Off by default +RETAIL_CONFIG_STRING_INFO(INTERNAL_EventSourceFilter, W("EventSourceFilter"), "") +RETAIL_CONFIG_STRING_INFO(INTERNAL_EventNameFilter, W("EventNameFilter"), "") #endif //defined(FEATURE_EVENT_TRACE) || defined(FEATURE_EVENTSOURCE_XPLAT) // diff --git a/src/mscorlib/src/System/Diagnostics/Eventing/XplatEventLogger.cs b/src/mscorlib/src/System/Diagnostics/Eventing/XplatEventLogger.cs index 4e380ee..d7112fc 100644 --- a/src/mscorlib/src/System/Diagnostics/Eventing/XplatEventLogger.cs +++ b/src/mscorlib/src/System/Diagnostics/Eventing/XplatEventLogger.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Text; using System.Runtime.InteropServices; +using System.Runtime.Versioning; using Contract = System.Diagnostics.Contracts.Contract; @@ -15,6 +16,9 @@ namespace System.Diagnostics.Tracing internal class XplatEventLogger : EventListener { + private static Lazy eventSourceNameFilter = new Lazy(() => CompatibilitySwitch.GetValueInternal("EventSourceFilter")); + private static Lazy eventSourceEventFilter = new Lazy(() => CompatibilitySwitch.GetValueInternal("EventNameFilter")); + public XplatEventLogger() {} private static bool initializedPersistentListener = false; @@ -122,12 +126,20 @@ namespace System.Diagnostics.Tracing internal protected override void OnEventSourceCreated(EventSource eventSource) { - EnableEvents(eventSource, EventLevel.LogAlways, EventKeywords.All, null); + string eventSourceFilter = eventSourceNameFilter.Value; + if (String.IsNullOrEmpty(eventSourceFilter) || (eventSource.Name.IndexOf(eventSourceFilter, StringComparison.OrdinalIgnoreCase) >= 0)) + { + EnableEvents(eventSource, EventLevel.LogAlways, EventKeywords.All, null); + } } internal protected override void OnEventWritten(EventWrittenEventArgs eventData) { - LogOnEventWritten(eventData); + string eventFilter = eventSourceEventFilter.Value; + if (String.IsNullOrEmpty(eventFilter) || (eventData.EventName.IndexOf(eventFilter, StringComparison.OrdinalIgnoreCase) >= 0)) + { + LogOnEventWritten(eventData); + } } [System.Security.SecuritySafeCritical] -- 2.7.4