6

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?

Jakob Gade
  • 12,319
  • 15
  • 70
  • 118

2 Answers2

2

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>
SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173
1

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.

Chris Dunaway
  • 10,974
  • 4
  • 36
  • 48