none
Console.WriteLine("asd"); does not write to output window

    Question

  • I am building a UserControl that is packaged in it's own DLL.  When I use the dll in a project and I test this control the line:

    Console.WriteLine(ctrl.Text);

    Does not output to the output window as it should.  I've experienced this phenomenon several times in the past when using external controls and I can't figure out why it would behave in this way.

    I know for sure that the line is being reached because I've tested it with a break point; however, when the line is executed no output is sent to the output window...  Any thoughts?
    Thursday, March 04, 2010 6:13 PM

Answers

  • Console.WriteLine doesn't output to the Output Window in Visual Studio(1), it outputs to the Console subsystem. If your DLL is loaded into a non-console application it has no where to write to.

    What you want is Trace.WriteLine. This writes via the operating system's OutputDebugString method. Not only will you see your output in Visual Studio, but you can download a program called DebugView that will allow you to see every program running on your machine's trace output.

    http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx


    (1) Visual Studio does attempt to redirect any console output to its output window, but it is not always successful.
    • Proposed as answer by Carlos Adriano Portes Saturday, March 06, 2010 1:38 AM
    • Marked as answer by Roahn Luo Monday, March 08, 2010 4:49 AM
    • Marked as answer by Roahn Luo Tuesday, March 09, 2010 8:10 AM
    Friday, March 05, 2010 2:06 PM

All replies

  • It is possible to redirect the Console output to another stream, or even set it to a kind of black-hole stream that just ignores anything written to it. It is possible that one of your external libraries does this. There really doesn't seem to be another explanation.

    You could use Red-Gate Reflector to see if they (these 3rd party controls) change the default output. You'd be looking for something along these lines:
    http://www.java2s.com/Code/CSharp/Development-Class/DemonstratesredirectingtheConsoleoutputtoafile.htm
    Thursday, March 04, 2010 7:30 PM
  • Is this an asp.net app?
    If so there is no default console (or if it is is being mapped to something on iis/casini dev server) and thus you wont see it in visual studio.

    iirc System.Diagnostics.Console will provide what you are lookign for;


    edit: if it is asp, then pop over to asp.net;
    If its not asp.net.. then appologies!
    km
    Thursday, March 04, 2010 8:13 PM
  • Well as per my understanding the control is in the dll & you are using the dll in your console app. Try writing the output to a file instead of the console. I hope you are using a console project itself else that would not solve your purpose of showing it outside.
    Friday, March 05, 2010 12:52 PM
  • Console.WriteLine doesn't output to the Output Window in Visual Studio(1), it outputs to the Console subsystem. If your DLL is loaded into a non-console application it has no where to write to.

    What you want is Trace.WriteLine. This writes via the operating system's OutputDebugString method. Not only will you see your output in Visual Studio, but you can download a program called DebugView that will allow you to see every program running on your machine's trace output.

    http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx


    (1) Visual Studio does attempt to redirect any console output to its output window, but it is not always successful.
    • Proposed as answer by Carlos Adriano Portes Saturday, March 06, 2010 1:38 AM
    • Marked as answer by Roahn Luo Monday, March 08, 2010 4:49 AM
    • Marked as answer by Roahn Luo Tuesday, March 09, 2010 8:10 AM
    Friday, March 05, 2010 2:06 PM
  • Thanks for the replies.  No It's not an asp.net application.

    Nor is it a console application. 

    It's a windows form application and Console.Writeline has always written to the Visual Studio output window in the past.  I don't really want to write to a file because checking the output in a file is too cumbersome.  

    I will try Tergivers solution it sounds like the most feasible.
    Friday, March 05, 2010 4:31 PM
  • I experience the same problem as described above. For simplicity and trouble shooting, I'm trying the following code in a C# console application in VS2010. Please note that of the three trace listeners, only the Console.Out works, the VS output window is empty (except for the usual debug message from the compiler and loader) and more concerning my mylogfile.txt remains at 0Bytes (empty), but does get created. I just can't get the trace nor the debug to write anything into my file and output window.

    Any thoughts?

            static void Main(string[] args)
            {
                TextWriterTraceListener myConsoleWriter = new
                TextWriterTraceListener(System.Console.Out);
                Debug.Listeners.Add(myConsoleWriter);
    
                TextWriterTraceListener myLogfile = new TextWriterTraceListener("mylogfile.txt");
                Debug.Listeners.Add(myLogfile);
    
                Debug.Listeners.Add(myLogfile);
    
                Debug.WriteLine("Writeline");
                Debug.Write("Write");
    
                Trace.WriteLine("Writeline");
                Trace.Write("Write");
    
                Console.ReadLine();
            }
    

    Monday, October 22, 2012 1:04 AM