Click here to Skip to main content
15,914,409 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
The black debug window was slowing me down significantly and I was only interested in the last 5 lines of the debug window. I was looking for a way to save the last 5 lines to an external file. Someone wrote me this solution but neglected to add the most important part of what I was looking for. They didn't show me how to create a file name and and location to save the last 5 lines of the debug screen.


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());
Posted

1 solution

You can use File.WriteAllText[^] method to write string to a file in given path, for example:
C#
string path = @"c:\temp\Log.txt";
File.WriteAllText(path, output);
 
Share this answer
 

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