Friday, 27 March 2009

Introduction to Log4Net


Log4net ( is a tool to help the programmer output log statements to a variety of output targets, i have used it handling all the logging requirements of the applications that i have developed recently. And have found it integrates very well with and NHibernate.

In most cases i have set up the apps to log everything to a file and also log errors/warnings to an SMTP logger (which effectively sends an email out to me).
There are loads of examples and manuals etc on the website it gives loads of good config examples too.

In order to get log4net working all you need is the log4net dll, configuration, and a small amount of code to get it started and logging. (this page is a good read

But the minimum to take away is:
1. Reference the log4net dll
2. Import the log4net classes
2.1. using log4net;
2.2. using log4net.Config;
3. Add a config file (usually just a section to your web.config or app.config)
4. Add a call to the configurator
4.1. log4net.Config.XmlConfigurator?.Configure();
4.2. Or [assembly: log4net.Config.XmlConfigurator?(Watch=true)]
5. Create a logger
5.1. private static readonly ILog log = LogManager?.GetLogger?(typeof(MyClassName?));
5.2. each class should have its own logger, which should be private and static (log4net is thread safe)
6. Use the logger to log
6.1. log.Info("my info message.");

If you find you are getting double entries for log records it is probably due to you having duplicated entries in the log config. For example you might have the root set to debug logging and a named logger also set to debug, which will mean that 2 log entries get inserted for all debug messages from that named logger.

Tuesday, 24 March 2009

How to expand a virtual machines disk space

There comes a time when everyone who uses virtual machines runs out of space.
I use virtual machines for my dev environment, which means i can mess around with them, install things to test them out safe in the knowledge that you can always get back to a previous state, or even back to the start with out any pain at all.
ive got a VM for VS2003 one for VS2008, i used to have one for VS2005 (but i don't use that any more) and dare i say it one for VB6 (which thankfully ive not used for quite a while)
But recently i ran out of space on the VS2008 install, id also got office installed, and i wanted the 3.5 framework sp1 installing, which is surprisingly large.
well, this is what i did:
open up a command line
vmware-vdiskmanager.exe -x 16Gb "C:\VMWare\WinXPPro5\Windows XP Professional.vmdk"
boot up from an ubuntu 8.04 live cd
bring up command console
type sudo gparted
select your main partition
right click partition to be expanded and hit resize
move slider to the right for the whole of the disk
exit ubuntu
restart xp
enjoy your new many gigs of space