views:

260

answers:

2

My envirorment is Visual Studio 2005. My specifically problemis I want to define TRACE.

I have a Web Site Project that send trace messages when run out of the ASP.NET Development Server thanks to defining it in the system.codedom element of the web.config.

When I deploy to IIS, I do so via a web deployment project. So the site is precompiled. Naturally, these entries serve no purpose on a compiled website. My question is how do I define TRACE in the web deployment project.

+1  A: 
Justin Dearing
A: 

There is no equivalent to #defines in C#. That said, it sounds like you want to use conditional tracing, which is easily accomplished. If you have diagnostic code throughout your project but want to define it, use the built in trace functionality, for example

System.Diagnostics.Trace.WriteLine("Some debug output");

Then, in your webconfig, you can configure it on/off using

<configuration>
 <system.web>
  <trace enabled="true" requestLimit="40" localOnly="false"/>
 </system.web>
</configuration>

More info here

Serapth
Serapth,Thanks for your reply. I think I was unclear in my question though. I understand I can turn on ASP.NET tracing in the web.config and get the information showin in that link. However, what I want is for Trace.Trace(Information|Warning|Error)(message) to get sent to the trace listeners. That required TRACE to be defined. Also, #define works just fine in C#. Give it a try.
Justin Dearing