ASP.NET instrumentation (tracing) to a file

It's often helpful to instrument your code to help with troubleshooting, etc.  Instrumentation is really just a fancy word for tracing.

Here's an example of tracing to a file from ASP.NET.

<%@ Page Language="C#" CompilerOptions="/d:TRACE" %>
<script runat="server">
void Page_Load(object sender, EventArgs e)
                System.Diagnostics.Trace.WriteLine(String.Format("{0},{1}", DateTime.Now, "Hello world!"));

    <trace autoflush="true">
        <add name="mytrace" type="System.Diagnostics.TextWriterTraceListener" initializeData="c:\temp\mytrace.csv" />

If you'd like to avoid the CompilerOptions Page directive, an alternate technique is to add the following additional web.config entries.  Note, this is equivilent to adding the directive to every page in your ASP.NET application.

      <compiler language="c#;cs;csharp"
type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="1" />