Monday, April 8, 2013

New version of NLog released

In July last year, Jarek came with the announcement, that he would stop actively developing NLog and needed someone to take over. I thought it would be shame if one of the best logging frameworks for .NET died, so I started developing and maintaining.

This was half a year ago, and the last release were almost 2 years ago, so now it is time for a new version of NLog, version 2.0.1. This is purely a bug fix release, so everyone using NLog 2.0.0.2, should be able to upgrade to the new version.

For those interested in what has been fixed in v2.0.1, take a look at milestone 2.0.1 on GitHub. The new release can be downloaded from NuGet.

Thursday, January 31, 2013

Chain of Responsibility "Monad"

Most of us know design patterns, and most of us know Chain of Responsibility.

In my opinion this is a very useful pattern, but a lot of the implementation found online, have this feeling of oldness upon them.

The text book example is something like:

To me this seems old school. Sure it works, it's readable and well documented, but wouldn't you like something more like this instead?

At least I like it much better, and that is the most important :)

So how is this implemented? Well it is pretty straightforward, it consists of:

  • ChainElement<TOutput> which contains the result and whether it was handled or not.
  • IChain<TInput, TOutput> which is an interface defining a single part of the chain.
  • ChainExtensions which contains extension methods for chaining.

The whole implementation can be seen below:

The magic happens in the extension methods, it basically allows you to build a list and feed it an input until it's handled.

A handler could be implemented like this:

By: