Favourite Quote

Every artist was first an amateur. - Ralph Waldo Emerson The more difficulties one has to encounter, within and without, the more significant and the higher in inspiration his life will be. - Horace Bushnell

Tuesday, October 23, 2012

WebDriver C#,using log4net - logging

Most of us want our logs to be written to a file externally.

Whether they are application logs,console logs.

In our case have used to grab the logs for the WebDriver C# bindings using the log4net.dll's

Below are step by step instructions as to go about using log4net :

1. Add a config section in the app.config file under configuration

2. Add a appSettings section where you define a key value pair

Which would facilitate ConfigurationManager to get the value

3. I have created a config file other than that of the app.config & named it as log4net.config - below is the configuration

Have used RollingFileAppender and specified a location where these logs are to be written.

RollingFileAppender - This is just like LogFileAppender with an exception doesn't create a new file

Until it has reached the MaximumFilesize that we have configured initially

4. The below code snippet shows how we need to initialize the logger

private static readonly ILog log = LogManager.GetLogger(typeof());

5. Now accessing the key value pair from the app.config file

log4net.Config.XmlConfigurator.Configure(new FileInfo(ConfigurationManager.AppSettings["log4netConfig"]));
automationwithselenium.blogspot.com-Google pagerank and Worth


  1. Hello Shabana, can you please share the code. when i tried to implement the logger as said by you i am getting error in my test project.

    Error 1@ typeof()--> Type expected
    Error 2@ ConfigurationManager.AppSettings["log4netConfig"]) --> ConfigurationManager does not exists in current context.

    please help...

    1. @Raj

      have you added log4netConfig in your appSettings ?

  2. I am working with a Selenium .dll project with no app.config. How do I configure log4net to work with my Selenium test .dll or is this not possible?