简体   繁体   English

将控制台附加到运行ASP.NET应用程序

[英]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. 假设我有一个库,我在其中添加了一些Console.WriteLine(..)语句来帮助我在实现过程中看到我在Console App中使用库时发生了什么。

Now I want to use the same library in an ASP.NET app. 现在我想在ASP.NET应用程序中使用相同的库。 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 . 您需要使用Trace语句并附加TraceListener

You can try TextWriterTraceListener . 您可以尝试TextWriterTraceListener initializeData is the path to where the log file will be written. initializeData是日志文件写入的路径。 Note: The App Pool Identity user will require write permission to this path. 注意:App Pool Identity用户将需要对此路径的写入权限。

<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查看跟踪发生的时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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