Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
The debug window is slowing me down severely, but all I want to see from it is the last few lines. I would like to not run the debug window and send the last 5 lines of the debug window to an external text file. Can someone please show me how to do this?
Posted

1 solution

C#
            StringBuilder sb = new StringBuilder();

            StringWriter sw = new StringWriter(sb);

            TextWriterTraceListener myWriter = new TextWriterTraceListener(sw);

            Debug.Listeners.Add(myWriter);
//...


            string output = string.Join("\n",
                sb.ToString().Split('\n').Reverse().Take(5).Reverse());


The last line is likely to be empty so you may want to exclude empty rows from the set of rows in the stringbuilder.
 
Share this answer
 
Comments
computerpublic 18-May-15 17:13pm    
I don't see where you named and created any external file?? How do you do this??
Andy Lanng 19-May-15 4:08am    
Really!?!

I gave you gold. Writing to an external file from a string is SO common you can google it: https://msdn.microsoft.com/en-us/library/8bh11f1k.aspx
computerpublic 23-May-15 10:21am    
I still cannot figure out how to complete what you wrote. I don't understand why you would write something incomplete.
Andy Lanng 26-May-15 4:23am    
Because it's not my place to write your code for you. That's not what this site is about.
You really can't work out how to write text to a file? Maybe you should post a new question. Please include in the question exactly where you are stuck.
Sergey Alexandrovich Kryukov 29-May-15 10:42am    
Ah, now I see: I guess you were the one who misled our inquirer to this trash:
http://www.codeproject.com/Questions/995247/Trying-to-Write-from-Debug-window-to-External-File.

Please don't get me wrong: I don't blame you, but perhaps you have to ask the inquirer what he is trying to do and why this debug window at all, why using Debug and Trace. And then I tried to answer next question, at least until this person lost patience and started to play rude:
http://www.codeproject.com/Answers/995255/Trying-to-Write-from-Debug-window-to-External-File#answer1.

Your advice to post a new question did not work :-(

—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900