Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. I've done a fair amount searching using Google with this issue, but nothing I've done works. Here is the 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>
like image 795
Halcyon Avatar asked Nov 04 '22 20:11

Halcyon


2 Answers

(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.

like image 60
CodesInChaos Avatar answered Nov 12 '22 18:11

CodesInChaos


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.

like image 29
chaospixel Avatar answered Nov 12 '22 19:11

chaospixel