Click here to Skip to main content
15,843,031 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have been trying for days to write the last 5 five lines of the debug window into an external text file. No matter what I do, it fails. Now I am having issues with the third line from the bottom "sb.ToString().Split('\n').Reverse()" underlined in red. The ERROR Reads: No overload for method 'Reverse' takes 0 arguments. I don't know what this means and I don't know how to fix it. Can someone please help.

using System;
using System.IO;
using System.Text;
using System.Diagnostics;
using System.Collections;
namespace Applica
    static class Program
        static void Main(string[] args)
            byte[] data = new byte[] {1,2,3,4,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,72,101,108,111,13,10};
            for (int i = 0; i < 28; i++)
                StringBuilder sb = new StringBuilder();
                StringWriter sw = new StringWriter(sb);
                TextWriterTraceListener myWriter = new TextWriterTraceListener(sw);
                string output = string.Join("\n", sb.ToString().Split('\n').Reverse().Take(5).Reverse());
                string path = @"c:\temp\Log.txt";
                File.WriteAllText(path, output);
ZurdoDev 26-May-15 16:21pm    
Reverse is a static method on Array and not to be used on this instance.


So, you would call Array.Reverse(sb.ToString().Split('\n'));
Sergey Alexandrovich Kryukov 26-May-15 17:27pm    
The whole idea of writing lines of some window to a file is wrong. You are not writing anything "from a window". You just write some data to file.

1 solution

Your problem is: you are correctly using TextWriterTraceListener, but it is used for tracing or debugging output. But you are not writing anything to Trace, so there is nothing to capture. The whole code simply makes no sense.

Read MSDN documentation thoroughly, pay attention for the code sample, read all about it and also Trace and Debug:[^],[^],[^].

Share this answer
computerpublic 27-May-15 5:53am    
I have read the msdn's and looked at the examples. I dont understand why you say I am not writing anything to Trace. Can you show me how to fix the String Output line?
Sergey Alexandrovich Kryukov 27-May-15 9:09am    
Because you don't show any Trace code. Where?
If you simply want to do output, do it, why capturing anything (nothing, in this case)?
Again, look at the code sample.
computerpublic 28-May-15 0:48am    
The following is the only example that comes anywhere close to what i am trying to accomplish, however I don't understand how to put the last 5 lines of the debugger inside it.
// Create a file for output named TestFile.txt.
Stream myFile = File.Create(@"c:\check\TestFile.txt");
//* Create a new text writer using the output stream, and add it to
// * the trace listeners.
TextWriterTraceListener myTextListener = new TextWriterTraceListener(myFile);
//Write output to the file.
// Flush the output.

Sergey Alexandrovich Kryukov 28-May-15 0:53am    
All right, this is completely different story: Trace is used. And I explain why your code sample produces no content in the file: because nothing was sent to output. Isn't that clear? If it is, will you accept the answer formally?
computerpublic 28-May-15 19:41pm    
I still do not understand how to get the last 5 lines of the debugger. Its been several days. I did as you told me and I am still stuck. What exactly do you want me accept? I just to get the thing to work. Can you show me how to get the last 5 lines of the debugger into an external file?

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