#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)
//
using System.Diagnostics;
using System.Text;
using System.Runtime.InteropServices;
+using System.Runtime.Versioning;
using Contract = System.Diagnostics.Contracts.Contract;
internal class XplatEventLogger : EventListener
{
+ private static Lazy<string> eventSourceNameFilter = new Lazy<string>(() => CompatibilitySwitch.GetValueInternal("EventSourceFilter"));
+ private static Lazy<string> eventSourceEventFilter = new Lazy<string>(() => CompatibilitySwitch.GetValueInternal("EventNameFilter"));
+
public XplatEventLogger() {}
private static bool initializedPersistentListener = false;
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]