static void Main() { oldCol = Console.ForegroundColor; SetConsoleCtrlHandler(ExitHandler, true); try { Console.WriteLine("**** Create EventSources ****"); SourceA = MetricsFactory.GetCustomMetricsService("SourceA", 1.0, true); SourceB = MetricsFactory.GetCustomMetricsService("SourceB", 3.0, true); SourceC = MetricsFactory.GetCustomMetricsService("SourceC", 7.0, true); Console.WriteLine("**** Issue Description ****"); Console.WriteLine( "Each EventSource has is own Default Listener but it appears that ALL EventListeners get ALL EventCounter events.\r\n" + "So rather than having a single highlight color per event to indicate the expected filtering,\r\n" + "the following event logging will show multiple highlight colors within a single line:"); Console.WriteLine("***************************"); var random = new Random(); for (int i = 0; i <= 40000; i++) { SleepingBeauty(random.Next(10, 200)); } Console.ReadKey(); } finally { Console.ForegroundColor = oldCol; } }
/// <summary> /// Hook up an EventListener for the passed ICustomMetricsService EventSource /// </summary> /// <param name="metricsService"></param> /// <param name="updateRateSeconds"></param> /// <param name="collectMetrics"></param> /// <returns></returns> private static EventListener RegisterCustomMetricsEventListener(ICustomMetricsService metricsService, double updateRateSeconds, bool collectMetrics) { var eventSource = metricsService as EventSource; var reader = new CustomMetricsEventListener(); var arguments = new Dictionary <string, string> { { "EventCounterIntervalSec", updateRateSeconds.ToString(CultureInfo.InvariantCulture) } }; reader.EnableEvents(eventSource, EventLevel.LogAlways, EventKeywords.None, collectMetrics ? arguments : null); return(reader); }