示例#1
0
        static void Main(string[] args)
        {
            var reader    = new CustomMetricsEventListener();
            var arguments = new Dictionary <string, string>
            {
                { "EventCounterIntervalSec", "1" }
            };

            reader.EnableEvents(CustomMetricsEventSource.Log, EventLevel.LogAlways, EventKeywords.All, arguments);

            var random = new Random();

            var cts = new CancellationTokenSource();

            Task.Run(() =>
            {
                while (!cts.IsCancellationRequested)
                {
                    SleepingBeauty(random.Next(10, 200));
                }
            });

            Console.WriteLine("Press any key to stop");
            Console.ReadKey();

            cts.Cancel();

            CustomMetricsEventSource.Log.ApplicationStop();
        }
示例#2
0
        /// <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);
        }