Attaching console to running ASP.NET app

Let’s say I have a library, in which I added a few Console.WriteLine(..) statements to help me out during the implementation and see what’s going on when I use the library in a Console App.

Now I want to use the same library in an ASP.NET app. Ideally I would be able to log on to the production webserver, and somehow start a command prompt and attach it to the website and see the messages in real time as they occur. How do I do that?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You can’t – there is not such thing as a console on the server. You need to use Trace statements and attach a TraceListener.

You can try TextWriterTraceListener. initializeData is the path to where the log file will be written. Note: The App Pool Identity user will require write permission to this path.

<configuration>
  <system.diagnostics>
    <trace autoflush="false" indentsize="4">
      <listeners>
        <add name="myListener" 
          type="System.Diagnostics.TextWriterTraceListener" 
          initializeData="TextWriterOutput.log" />
        <remove name="Default" />
      </listeners>
    </trace>
  </system.diagnostics>
</configuration>

Method 2

I’m not sure it works with ASP.Net, but you can use Trace.WriteLine instead of Console.WriteLine and then use DebugView to view the traces as they happen.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x