开发者

Using System.Diagnostics.Debug In An ASP.NET Application

开发者 https://www.devze.com 2023-03-12 21:49 出处:网络
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. I\'ve done a fair amount searching

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. I've done a fair amount searching using Google with this issue, but nothing I've done works. Here is th开发者_运维技巧e code in my ASPX page:

List<MyClass> myClasses = GetMyClasses();
foreach (MyClass myClass in myClasses)
{
    Debug.WriteLine(myClass.SomeProperty);
}

The code is very straight-forward. When I debug this page, myClass.SomeProperty has the value I want, but nothing is getting printed to the output window. What could I be missing? I cannot use a Response.Write because my Response stream is being used to create an Excel file. I also don't want to use Tracing.

Update

I have this in my web.config file:

<system.web>
    ...
    <compilation debug="true" targetFramework="4.0">
    ...
</system.web>


(Sorry no full answer, but a bit long for a comment)

There are debug related features. (Related What does the optimize switch do)

  • Generation of debug Symbols
  • C# IL optimization
  • Jitter Optimization
  • The DEBUG conditional define.

What you need for your problem is the DEBUG conditional. I guess the debug="true" switch affects only the debug symbols but not the conditional.


edit: hmm strange. scottgu states at http://weblogs.asp.net/scottgu/archive/2005/11/06/429723.aspx that debug="true" should affect that conditional.

Note that the value of debug in a web app is driven by the value of the value in your web.config file.


You are using System.Diagnostics.Trace, rather than the ASP.NET Tracing. To get System.Diagnostics.Trace working within ASP.NET see http://msdn.microsoft.com/en-us/library/b0ectfxd(v=vs.85).aspx.


I also had a same issue but later found out that Debug.Writeline() didn't work with my unit tests.


Have you set

<system.web> <compilation debug="true" defaultLanguage="c#" />  </system.web>

in your web.config?

0

精彩评论

暂无评论...
验证码 换一张
取 消