Google Website Translator Gadget

Tuesday, 31 August 2010

Threading in C# – Free E-book Updated

2325664001_ef61441ab7_m This is just a quick post to highlight the fact that Joseph Albahari, author of the excellent LINQPad and C# 4.0 In A Nutshell book, has recently updated hits free Threading in C# e-book.  The e-book contains some really great, concise content on all the latest threading related topics in .NET.  The latest version includes coverage of new .NET 4.0 constructs like ThreadLocal<T> and Lazy<T> as well as a whole chapter dedicated to the new Parallel Programming extensions to the .NET framework.  Highly recommended!

Sunday, 29 August 2010

Log4View – Getting the most out of your log4net/log4j log files

If you are using log4net or log4j for writing log files, do yourself a favour and get the whole team and production support a copy of Log4View as soon as possible.  It really is a wonderful tool that sits on top of your log4net or log4j files to give you a birds-eye view on what’s happening in your application.  Need to monitor your servers remotely as they are running?  No problem, just add a reference to their TCP log appender that allows you to configure log4net to log all statements to a TCP port.  This gives you the flexibility of remotely monitoring the server as the application is running in production (providing you open the port on the firewall of course). 

One of the most powerful features IMO is the grouping feature in the message view.  Look at the following screenshot that shows how easy it is to group messages according to session id/thread id or any other custom log information added to your log files.  Simply drag the columns you want to group by into the Group By area above the grid:

log4view grouping

This specific grouping allows us to easily inspect the separate requests associated with a certain user in the system. Highly recommended!

RunSharp – IL Generation for Dummies

We’ve been doing some interesting work the past 2-3 weeks on creating a Rule Engine for our company’s flagship product, On Key.  The Rule Engine needs to evaluate rules entered by the end user at run-time according to our pre-defined grammar to determine a true/false answer.  This allows us tremendous flexibility in that end-users are able to specify under which conditions certain actions should occur within the system.  The main requirements for the technical solution was that it should be as quick as possible but it also has to cater for rules being changed at run-time by the end-users.  

Before heading off to create our own custom solution, we did some research to consider possible solutions to solving the same kind of problem.  Some of the solutions we came across were:

  1. Flee
  2. NCalc
  3. Irony
  4. Dynamic method generation using Expression Trees 

After looking at all of these solutions, we decided to rather create our own to give us the ultimate control and flexibility over extending the Rule Engine going forward.  Setting up the grammar using the excellent ANTLR and ANTLRWorks was quite easy to do.  ANTLR takes care of generating the C# code that will do the lexing, parsing and type checking of the rules entered by the user.  Thereafter we moved onto the run-time evaluation/compilation of the rules represented in the Abstract Syntax Tree created by ANTLR.  For this purpose, we created 3 tree walkers/visitors on our AST to compare against each other:

  1. Interpreter – Evaluate the rules dynamically as we walk the AST
  2. C# Code Generator – Walk the tree and generate C# code that is compiled using the C# compiler into an assembly
  3. IL Code Generator – Walk the tree and generate dynamic IL code in memory