Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 811
Jakob Gade Avatar asked Nov 04 '11 04:11

Jakob Gade


2 Answers

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>
like image 199
SliverNinja - MSFT Avatar answered Nov 05 '22 03:11

SliverNinja - MSFT


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.

like image 37
Chris Dunaway Avatar answered Nov 05 '22 05:11

Chris Dunaway