Freigeben über


Keeping Traces Up to Date

I've enabled tracing in my application, but I don't see entries in the trace log show up until I restart IIS. How can I get trace entries to appear right away?

Like many other output files, traces are buffered to reduce the number of times that the disk has to be accessed to write out the data. It's possible that the trace log will be incomplete until something triggers writing out those traces that been buffered. This behavior impacts people differently depending on how they're debugging their applications. For instance, if you've got a self-hosted application that you're starting up, running a few tests, and shutting down, then this doesn't really impact you at all. Closing the application will write out the remaining traces.

On the other hand, applications hosted in IIS tend to be impacted more. When hosting with IIS, you have less control about the lifetime of your application, including when it gets started and stopped. Even though you're done testing, IIS may be keeping your application alive and running, which prevents triggering the write out of remaining traces. You can work around this by restarting IIS and forcing everything to get shut down. However, if there are other applications running on the machine, then this can be painful.

Another thing you can do is turn off the buffering of traces and take the slight performance hit of accessing the disk more frequently. Trace buffering (or really the lack of buffering) can be controlled through diagnostics configuration. This is another entry in the standard configuration file for your application, this time using the system.diagnostics namespace.

 <configuration>
  <system.diagnostics>
    <trace autoflush="true" />
  </system.diagnostics>
</configuration>

Next time: Modifying HTTP Error Codes, Part 1

Comments

  • Anonymous
    January 22, 2007
    Another thing you can do is have a special page in your app, say TraceFlush.aspx, that calls the Trace.Flush() method. Then you can just request this page (e.g. in a separate browser window) whenever you want to look at the latest trace data.  And you don't get the performance hit of autoflush.

  • Anonymous
    January 22, 2007
    Last time we were looking at the problem of securing a dynamically generated message header . We saw