Examples of log4net PatternLayout output

Sunday, 24 May 2009

log4net has a lot of options when it comes to defining what you write to your log. While all the patterns are documented, it is useful to see a sample output from some code. Here is the output produced from some of the patterns available:

Pattern Class ‘BaseClass’ Class ‘SubClass’
appdomain log4netPatterns.vshost.exe log4netPatterns.vshost.exe
date 2009-05-24 16:37:26,578 2009-05-24 16:37:26,640
file C:\Dev\GoogleCode-Gardiner\trunk\Log4netPatterns\log4netPatterns\Program.cs C:\Dev\GoogleCode-Gardiner\trunk\Log4netPatterns\log4netPatterns\Program.cs
location log4netPatterns.BaseClass`1.MyMethod(C:\Dev\GoogleCode-Gardiner\trunk\Log4netPatterns\log4netPatterns\Program.cs:32) log4netPatterns.SubClass.MyMethod(C:\Dev\GoogleCode-Gardiner\trunk\Log4netPatterns\log4netPatterns\Program.cs:49)
line 32 49
logger log4netPatterns.BaseClass`1[[System.Int32, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089]] log4netPatterns.SubClass
message BaseClass SubClass
method MyMethod MyMethod
property {log4net:HostName=morgan} {log4net:HostName=morgan}
timestamp 45968 46015
thread 2116 2116
type log4netPatterns.BaseClass`1 log4netPatterns.SubClass
username MORGAN\David MORGAN\David
utcdate 2009-05-24 07:14:41,468 2009-05-24 07:14:41,515

Of particular interest is the difference between logger and type. For the SubClass class, they result in the same output, but for the BaseClass logger is a lot more verbose (especially if your generic type happens to be from a strongly-signed assembly!). Using logger will give more detailed information but at the expense of larger log files.


Because some of the patterns vary their output if you are in a base class or an inherited class, I created a simple class hierarchy, and also included use of generics.

public class BaseClass<T>
   private ILog _log;

   public BaseClass()
       _log = LogManager.GetLogger(typeof (BaseClass<T>));

   public virtual string MyMethod(T stuff)

       return "ha";

public class SubClass : BaseClass<string>
   private ILog _log;

   public SubClass()
       _log = LogManager.GetLogger(typeof (SubClass));

   public override string MyMethod(string stuff)

       return "ho ho";

The project that included this code was strongly signed, to allow any effect this might cause to be evident.

Blog moved to http://david.gardiner.net.au

Wednesday, 13 May 2009

I’ve decided to move my blog to a custom URL. It is still hosted by blogger, and the old address should continue to redirect to http://david.gardiner.net.au. If you are subscribed via a feed, then you shouldn’t need to change anything either.

I wonder what that will do to my page rank?

How to mock a serial port

Thursday, 7 May 2009

This question came up on the Rhino Mocks list recently, and it interested me as the application we’re working on has to talk to serial ports too.

Two common themes emerged:

  1. Write a “thin” interface for serial port operations and create a thin wrapper class that implements this interface and calls SerialPort directly. You can then mock out the interface easily.
  2. To test the wrapper, you can make use of the com0com null-modem emulator.

I suspect there would still be a bit of effort to get the com0com emulator working properly, but it sounds promising.

What a funny old fellow..

Tuesday, 21 April 2009

Ok, I thought the GFC was pretty bad, but this really indicates how tough things have got.

Humphrey B Bear (from The Age newspaper)

I really hope that’s not a “goodbye” wave :-(

Happy Birthday

Monday, 20 April 2009

Saturday was my birthday, and amongst other things I got these nice presents..

Pride and Prejudice Blu-Ray Cover

This is the re-mastered Blu-Ray edition of the 1995 BBC Production of Jane Austen’s Pride and Prejudice. I admit I am a bit of an Austen fan, and whilst Mr Darcy diving into the pond doesn’t seem to have the same effect on me as it does on many of the women I know, this is probably my favourite film adaptation. The icing on the cake is of course that Elizabeth’s nice Uncle and Aunty are Mr & Mrs Gardiner – Yay!

Pinocchio 70th Anniversary Blu-Ray Cover

Pinocchio – 70th Anniversary Edition. This film has special memories for me, and particularly so on my birthday. For growing up as a child, one of the highlights of my birthday party would be my Poppa showing his collection of short films on his Super-8 movie projector. In the era before video/DVD players, this was a real novelty. One of my favourite films was a short extract from Pinocchio - the bit where Pinocchio and Geppetto cause Monstro the whale to sneeze by lighting their fishing boat on fire (they were inside the whale at the time).

I ended up watching the whole movie in the afternoon, but the kids found it a bit scary in places. I’m not certain, but I think that may be the first time I’ve seen the entire movie.

Packet of Arnott's Iced Vovo biscuits

Finally, just the thing for completing any evening’s movie watching – a packet of Iced Vo-Vos. The iced biscuit of champions!