log4net on the Compact Framework

I was reminded of log4net today when working on a project. The client asked a logging framework and the cool part is that it’s a Compact Framework application. Sure enough log4net supports the Compact Framework.

There are a couple of minor differences that you should be aware of if you are interested in using log4net on the Compact Framework. First of all, not all of the appenders make sense – like the RemotingAppender, the EventLogAppender and the OracleAppender. Secondly, there is no mechanism for retrieving assembly level attributes so you have to explicitly initialize and shut down the log4net engine.


static void Main()




            //This line configures the log4net engine.


new FileInfo(@”\log4net.config”));


            frmLogin loginForm = new frmLogin ();


                  Application.Run(new frmMain());



      catch (System.Exception e)


            _log.Error(“Main“, e);




            //This line shuts down the log4net engine





The other thing that was interesting is that the online help on http://logging.apache.org/log4net showed conversion patterns with %message%newline to print the message and then put a newline in the file. I had to use %m%n because the first one there printed as


My stringessage



which was not quite what was expected.


Have fun with log4net, it’s a great lightweight logging framework for the compact framework.

Leave a Reply

Your email address will not be published. Required fields are marked *