Friday, August 21, 2009

log4net: No layout set for the appender named

I recently created a new ASP.NET web project and set it up to use log4net with a RollingFileAppender as its logging framework. However, at first my log file wasn't showing up at all and then after I got it showing up, my log statements were not being written. Fixing this involved two steps.

First, the DLL reference generated by Visual Studio did not automatically set the log4net assembly to copy local. Setting this property on the reference solved the issue of my log file not appearing.

Second, now that I had my file, I was not seeing any log statements written to it. Debugging the process, I saw the following error output from log4net:

AppenderSkeleton: No layout set for the appender named

Looking at my configuration file, I saw that I was setting an appender layout. However, I noticed that my appender layout was based on a type defined in a different project. Checking the reference to that project, I again found that Visual Studio was not copying a local version of the assembly, i.e. the Private flag was set to false. Switching this flag to true fixed the problem and now my logs are showing up!

Wednesday, August 19, 2009

Long Method Names

As code completion (or auto complete) has become more ubiquitous and second nature to most software developers, so also has the tendency to spend less time thinking critically about the names that we assign our variables and methods. In place of this, I have observed the likelihood to squeeze the entire purpose of the variable or method into the name (e.g. DoThisUnlessThatIsTrueAndBeGentle()). Perhaps we may soon have the entire algorithm of a method squeezed into a name (with the obvious advantage of not needing to read the method at all!). Have we lost (or forgotten) the advantage of abstracting the purpose of a variable or implementation of a method (or class) behind a simple, distinct name?

Disadvantages:
1. It's almost never possible to completely and accurately name a variable or method. Any attempt to do so may lead to more confusion.
2. Side-by-side comparisons of two versions of the same code become more painstaking with horizontal scrolling -- perhaps a bug is even missed because the developer is too lazy/busy to mess with the scrolling.
3. Constrained to multi-line formatting

Advantages:
1. More descriptive names?

I am often reminded of an article by Joel Spolsky (back when I read his stuff): http://www.joelonsoftware.com/articles/Wrong.html (scroll to the "I'm Hungary" section towards the bottom) when I ruminate on this subject.