Development ASP.Net Tutorial

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"  Inherits="Tracing" %>



    Untitled Page


    
    

    

Logging trace output to " />


    

    


File: Default.aspx.cs
using System;
using System.IO;
using System.Web;
using System.Configuration;
public partial class Tracing : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Trace.TraceFinished += Trace_Finished;
        Trace.Write("Using Page Trace", "Subscribed to TraceFinished event");
    }
    void Trace_Finished(Object sender, TraceContextEventArgs e)
    {
        string traceFile = ConfigurationManager.AppSettings["traceFile"];
        using (StreamWriter w = File.AppendText(traceFile))
        {
            int i = 0;
            foreach (TraceContextRecord r in e.TraceRecords)
                w.WriteLine("{0}) {1}:{2}", ++i, r.Category, r.Message);
        }
    }
}
File: Web.config