简体   繁体   中英

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?

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>

我不确定它是否适用于ASP.Net,但您可以使用Trace.WriteLine而不是Console.WriteLine,然后使用DebugView查看跟踪发生的时间。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM