![](/img/trans.png)
[英]Capture System.Diagnostics.Debug Output in a WCF application
[英]Using System.Diagnostics.Debug In An ASP.NET Application
I'm trying to see the output of a foreach loop in my code in the output window in an ASP.NET web app, but I don't get any results even though there is valid data. 对于这个问题,我已经使用 Google 进行了相当多的搜索,但我没有做任何工作。 这是我的 ASPX 页面中的代码:
List<MyClass> myClasses = GetMyClasses();
foreach (MyClass myClass in myClasses)
{
Debug.WriteLine(myClass.SomeProperty);
}
代码非常简单。 当我调试此页面时,myClass.SomeProperty 具有我想要的值,但没有任何内容打印到 output window。 我会错过什么? 我不能使用 Response.Write,因为我的 Response stream 正在用于创建 Excel 文件。 我也不想使用跟踪。
我的 web.config 文件中有这个:
<system.web>
...
<compilation debug="true" targetFramework="4.0">
...
</system.web>
您正在使用 System.Diagnostics.Trace,而不是 ASP.NET 跟踪。 要让 System.Diagnostics.Trace 在 ASP.NET 中工作,请参阅http://msdn.microsoft.com/en-us/library/b0ectfxd(v=vs.85).aspx 。
(抱歉没有完整的答案,但评论有点长)
有调试相关的功能。 (相关优化开关是做什么的)
您的问题需要的是DEBUG
条件。 我猜debug="true"
开关只影响调试符号,但不影响条件。
编辑:嗯,奇怪。 scottgu 在http://weblogs.asp.net/scottgu/archive/2005/11/06/429723.aspx中声明debug="true"
应该影响该条件。
请注意,web 应用程序中的调试值由 web.config 文件中的值驱动。
我也有同样的问题,但后来发现 Debug.Writeline() 不适用于我的单元测试。
你设置了吗
<system.web> <compilation debug="true" defaultLanguage="c#" /> </system.web>
在您的 web.config 中?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.