System.Diagnostics.TextWriterTraceListener with ASP.Net 4

I spent hours trying to figure out why my web app wasn't writing to a debug file.

I had this in my web.config

<system.diagnostics>
  <trace autoflush="true">
    <listeners>
      <add name="textLogListener" type="System.Diagnostics.TextWriterTraceListener"
           initializeData="myapp.log"  />
      <remove name="Default" />
    </listeners>
  </trace>
</system.diagnostics>


And in my .cs code added
System.Diagnostics.Trace.WriteLine("Hello World");

Worked great in VS2012 but when I published it to a server, no file was created.   

I'm guessing that the ASP.Net compiler wasn't using the trace and debug flags.  The simple fix was adding 

#define TRACE

to the top of the .cs file I was working with.

Simple but not obvious
Print | posted on Monday, February 2, 2015 2:40 PM