Revisiting ASP.NET logging and tracing solutions

It has been several years since I researched the logging and tracing solutions last time so I need a revisit. ASP.NET always had tracing that can be turned on at the page level through page directive or the application level through the web.config file. The trace output can be either appended to the end of a page and viewed via trace.axd. ASP.NET tracing is different to System.Diagnostic tracing. Fortunately, ASP.NET 2.0 or later allows integration between the two. Dino has an excellent article on this subject.

The ASP.NET tracing is most useful tracing events relating to page life cycle. For flexibility in filtering and sending trace data to different target, there are a few logging frameworks available, such as log4net, nlog and the Enterprise Library Logging Application Block. If an application can not be tied to a particular logging framework, then one can either use a common library, or roll your own.

In .net 2.0 or later, there is actually an enhancement to the static Trace class called TraceSource. TraceSource is quite flexible and it allows filter both on the writer side through TraceSwitch and on the listener side through listeners configuration and filter. For a comparison between TraceSource and other frameworks, see the discussion on stackoverflow. For projects that need to minimize external dependency, TraceSource is an excellent choice. The only limitation to the TraceSource solution is the availability of listeners. .net framework comes with the 10 listeners:

Microsoft.VisualBasic.Logging.FileLogTraceListener
System.Diagnostics.ConsoleTraceListener
System.Diagnostics.DefaultTraceListener
System.Diagnostics.DelimitedListTraceListener
System.Diagnostics.Eventing.EventProviderTraceListener
System.Diagnostics.EventLogTraceListener
System.Diagnostics.EventSchemaTraceListener
System.Diagnostics.TextWriterTraceListener
System.Diagnostics.XmlWriterTraceListener
System.Web.WebPageTraceListener

The KUADC project comes with 6 listeners:

SqlTraceListener
SmtpTraceListener
OutputDebugStringTraceListener
ConsoleTraceListener
CustomTraceListener
InMemoryTraceListener

There are a few other trace listeners such as TCPTraceListener and UDPTraceListener can be found on searching Google.

1 Comment

  • Hi, we just wanted to make you aware of a new service that is great for .net event logging. We are currently accepting beta testers, and would love a mention on your site. We are a fully hosted, and offer a great, fluent-style .net logging agent. Please check us out.

    Dave Weaver
    Loggr

Comments have been disabled for this content.