예제 #1
0
        private void LogToConsole()
        {
            var listener = ConsoleLog.CreateListener();

            listener.EnableEvents(MyEventSource.Log, EventLevel.LogAlways, EventKeywords.All);

            MyEventSource.Log.MethodOne("aaabbbccc", "ddd", "eee");
            MyEventSource.Log.MethodTwo(3.14);
            MyEventSource.Log.MethodThree("def");

            listener.DisableEvents(MyEventSource.Log);
            listener.Dispose();
        }
예제 #2
0
        private void LogToConsoleAdvanced()
        {
            var listener = ConsoleLog.CreateListener(new EventTextFormatter() /*new XmlEventTextFormatter()*/);

            //listener.EnableEvents(EventSourceSelfDescribing.Log, EventLevel.LogAlways, Keywords.All);
//            Extensions.EventListenerExtensions.EnableEvents(listener, "SelfDescribingEventSource", EventLevel.LogAlways, EventKeywords.All);
            listener.EnableEvents("SelfDescribingEventSource", EventLevel.LogAlways, EventKeywords.All);
            //listener.EnableEvents("System.Threading.Tasks.TplEventSource", EventLevel.LogAlways, EventKeywords.All);

            EventSourceSelfDescribing.Log.MethodOne("aaabbbccc", new[] { "ddd", "eee" });
            EventSourceSelfDescribing.Log.ActivityStart("Starting child activity");
            EventSourceSelfDescribing.Log.MethodTwo(3.14, new Dictionary <string, int> {
                { "twentyone", 21 }, { "twentytwo", 22 }
            });
            EventSourceSelfDescribing.Log.ActivityStop("Stopping child activity");
            EventSourceSelfDescribing.Log.MethodThree("def", new MyEventData {
                PropertyOne = "p1", Texts = new[] { "text1", "text2" }
            });

            //listener.DisableEvents("System.Threading.Tasks.TplEventSource");
            listener.DisableEvents("SelfDescribingEventSource");
            listener.Dispose();
        }