My problem is similar to one posed by Joel Coehoorn some time ago when he wanted to Redirect Trace Output to Console.
In my case, I'd like to output to a ListView or TextBox or for th开发者_开发技巧at matter, any control which can accept text. For this purpose, I'd like to have a general purpose Trace/Debug listener which I can hook to in order to process the messages (convert to a ListViewItem or something) before outputting it.
Is there any way I can achieve this or do I have to build my own Trace Listener?
If it's worth noting, I run VS2010 ultimate & VS2008 professional.
Solution should be in preferably be in VB.NET but C# is okay.
You could implement your own TraceListener class. Walkthrough here
You could just implement the Write and WriteLine methods to do this. Initializing it would look something like this:
var myTraceListener = new ListViewTraceListener(listView);
Trace.Listeners.Add(myTraceListener);
Of course, this is assuming your class has a constructor that accepts a ListView.
精彩评论