Using and extending System.Diagnostics trace logging

 

Essential.Diagnostics contains additional trace listeners, filters and utility classes for the .NET Framework System.Diagnostics trace logging. Included are colored console (that allows custom formats), SQL database (including a tool to create tables), formatted rolling file trace listener, rolling XML trace listener and in-memory trace listeners, simple property and expression filters, activity and logical operation scopes, and configuration file monitoring.

Download

The preferred method to integrate Essential.Diagnostics with your project is via the Essential.Diagnostics Configuration NuGet package, which contains sample config file sections plus includes the binaries needed to use the extensions (the binary files are also in the Binaries only download on CodePlex).

For the example project, which runs using Visual Web Developer 2010 Express, download the Essential.Diagnostics Complete package from CodePlex. The examples project contains a reference to the NuGet package.

Background

The .NET Framework System.Diagnostics provides powerful, flexible, high performance logging for applications -- and the core capabilities are already built into the .NET Framework!

This project uses the inbuilt features of the System.Diagnostics namespace, and shows how logging and tracing can be integrated into a client application by taking advantage of existing .NET Framework features.

This project also provides a library that enhances System.Diagnostics through it's numerous built-in extension points, but shouldn't require any changes to existing code (that uses the .NET Framework logging) to use some or all of the features.

Extension features provided by this project are marked EX -- other features are already provided by the .NET Framework you are using right now.

To see how you can use System.Diagnostics and the Essential.Diagnostics extensions see Getting Started and the Logging Primer.

Features

The .NET Framework System.Diagnostics, along with the extensions here, provides the following key features, or see a comparison with other logging frameworks.
  • Multiple logging sources.
  • Output to multiple trace listeners with different filtering.
  • Logical operation context and activity correlation.
  • Multiple levels of event types including activity tracing.
  • Integration with existing .NET Framework tracing (such as WCF).
  • Proven architecture.
  • Flexible and extensible design.
  • High performance.
  • No change required to existing .NET Framework trace statements.

The Framework and extensions can be used to write information to any of the following Listeners:

Log information can be custom formatted and include context information such as:
  • Event id, type, and message
  • Source - allows you to partition your logs
  • Event time and date
  • Thread id, process id and call stack
  • Logical operation stack, activity id, and correlation
  • Machine name, user name and Windows Identity EX

About

Last edited Apr 18, 2013 at 8:07 AM by sgryphon, version 20