Essential.Diagnostics v2

I have made significant changes in the organisation of the Essential.Diagnostics project; although none of the actual implementations have changed, the project has been split into separate packages for each trace listener, available via NuGet.

The packages are available on NuGet (Essential.Diagnostics), and the source code on CodePlex (Essential.Diagnostics).

The project also has a new logo:


What is Essential.Diagnotics?

Essential.Diagnostics is a collection of extensions to the .NET Framework System.Diagnostics, most additional trace listeners to fill the gaps in the Framework provided ones, e.g. a ColoredConsoleTraceListener, with custom formatting and color, a RollingFileTraceListener with custom formatting, and a SqlDatabaseTraceListener.

It also includes a Core packaged with a few utility classes such as a configuration file watcher, a generic expression filter, and a base class that makes it easy to add custom listeners.

The project also includes a completely separate Fluent package, which provides logging scopes, abstractions, and templated (generic) classes, to make using System.Diagnostics a bit easier and bit more friendly for dependency injection. This library is independent of the trace listeners.

Why update this library when .NET Core / Microsoft.Extensions.Logging is now out?

For new projects, from .NET 4.5.1 onwards, I would recommend using ILogger from Microsoft.Extensions.Logging.Abstractions in your code, instead of the older TraceSource. (Although if you are writing a library, you might also consider LibLog, which is a source-level solution.)

The Microsoft.Extensions.Logging.Abstractions packaging largely replaces the ITraceSource and ITraceLog abstractions from the Essential.Diagnostics.Fluent package, so I don’t expect that to see much use going forward.

However Microsoft.Extensions.Logging only really deals with capturing logging, not outputting it.

An easy solution, if working in .NET 4.5.1 or above, is to use Microsoft.Extensions.Logging.TraceSource to forward the events to TraceSource, especially if you are integrating with older .NET components. For these projects the various trace listener packages are still very useful. (I have updated the examples in the source code on CodePlex with a .NET 4.5.1 example that uses Extensions.Logging and outputs to ColoredConsoleTraceListener.)

Finally, there are still vast numbers of “legacy” .NET 2.0 through .NET 4.5 projects that could benefit from the goodness of easy to add NuGet packages.

The packages…

Okay, so here are the available trace listener packages. Each package installs the relevant library and also a sample config file section that details the various configuration options. (The SqlDatabaseTraceListener package also includes a command line tool that can create the default database and table — although that also can be customised.)

PM> Install-Package Essential.Diagnostics.BufferedEmailTraceListener
PM> Install-Package Essential.Diagnostics.ColoredConsoleTraceListener
PM> Install-Package Essential.Diagnostics.EmailTraceListener
PM> Install-Package Essential.Diagnostics.InMemoryTraceListener
PM> Install-Package Essential.Diagnostics.RollingFileTraceListener
PM> Install-Package Essential.Diagnostics.RollingXmlTraceListener
PM> Install-Package Essential.Diagnostics.SqlDatabaseTraceListener

All the above trace listener packages depend on the Core package, which has a base listener class, as well as the expression filter and file configuration watcher. Usually it is installed automatically with one of the above listeners, but it can also be installed separately if needed:

PM> Install-Package Essential.Diagnostics.Core

There is also a separate package that has the scope utility classes, abstractions, and templated classes for easy use with dependency injection. This package makes using System.Diagnotics trace sources easier, and can be used either separately (with system trace listeners), or in conjunction with the extended trace listeners above. As mentioned, if using .NET 4.5.1 or above, the Microsoft.Extensions.Logging.Abstractions package is probably a better choice.

PM> Install-Package Essential.Diagnostics.Fluent

What next?

Well, you should go and start using Essential.Diagnostics, of course!


  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: