Console.WriteLine在ASP.net生产环境中的位置? [英] Where does Console.WriteLine go in ASP.net production environment?

查看:121
本文介绍了Console.WriteLine在ASP.net生产环境中的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在IIS中部署asp.net Web应用程序之后,是否有机会看到Console.WriteLine命令的输出? (不再使用Visual Studio)

Is there any chance that I can see the output of Console.WriteLine command after deploying my asp.net web application in IIS? (no more Visual Studio)

我检查了以下问题:

Console.WriteLine在ASP.NET中的位置在哪里?

但是问题是他们都在谈论调试/开发环境,Visual Studio的输出窗口可以用来检查这些行的输出。

But the problem is that they all talk about debugging/development environment which output window of Visual Studio can be used to check the output of those lines.

是否真的有一种方法可以查看这些行的输出而无需安装额外的日志记录工具(例如log4net)?

Is there really a way to view the output of those lines without installing extra logging tools (e.g. log4net)?

推荐答案

Console.WriteLine(默认情况下重定向到Console.Out.WrlteLine)写入 Stream.Null ,表示根据您提到的问题

Console.WriteLine (which redirects to Console.Out.WrlteLine by default) is written to Stream.Null, meaning things written to them are lost, as per the question you mention.

要重定向 Console.Out 到另一个流(例如文件),请使用 Console.SetOut ,例如位于global.asax文件 BeginRequest处理程序。这会将所有Console.WriteLine调用重定向到输出文件。记住要在EndRequest处理程序或类似位置关闭流。

To redirect Console.Out to another stream, such as a file, use Console.SetOut, such as in the global.asax file BeginRequest handler. This will redirect any Console.WriteLine calls to the output file. Remember to close the stream in the EndRequest handler or similar location.

正如其他人在这里所说的,通常应避免在Web应用程序或通用库中使用Console.WriteLine作为这个原因。考虑使用日志记录库,例如 log4net

As others have said here, Console.WriteLine should be generally avoided in a web application or general purpose libraries for this reason. Consider using a logging library, such as log4net.

这篇关于Console.WriteLine在ASP.net生产环境中的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆