Thursday, February 02, 2006

Programmatically changing log file names in Log4net

I am working on a side Windows Forms project that of course I need logging in. I had spent some time looking at log4net to use as a common logging framework for all the apps we build at my company, so I thought I could save some time instead of rolling my own. Plus I have an aversion to the MS Enterprise Library, seems like you get a whole lot of "tax" just to get something like logging. So I integrated log4net into my Windows Forms project because I really wanted to RollingFile appender. log4net is all configuration based. You can either embed the configuration in your app.config or in a seperate log file. This includes the path and name of the file to log to with the RollingFile appender. Trouble is I don't know the path until run-time because it is dependent on the user's profile directory. Unfortunately, the IntelliSense on the log4net objects provide no obvious way to get to the appenders, no obvious way that is unless you completely understand their "repository" concept. Thankfully, someone else does: Programmatically changing log file names in Log4net This works like a charm and I am extremely happy with it.