How to generate logs with CodedUI?

Why logs? Well, it helps to debug the problem in our script. Usually logging and capturing the screenshots are not enable by default with CodedUI and to make it, we need to make some set up.

Follow the below steps to enable logging and capturing the screenshots-

1: Go to C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE location and search for ‘QTAgent32_40.exe.config’ and ‘QTAgent32.exe.config’. Make sure you have edit permission for these config files.

2: Modify the value for ‘EqtTraceLevel‘:


3: Add App.config file in your project and add the following code under the configuration node:


4: Add following code in CodedUITest1.cs file-


5: Now run the test.

6: Open Test Explorer and click on Output hyperlink-


7: Click on UITestActionLog.html link.


8: Now check your script logs-



Logging with Log4J

Log4j is widely used API for generating the logs and there are few steps to configure it with Selenium Webdriver.

  • Download the latest log4j api from here.
  • Include the log4j-1.2.XX.jar file in your project build path.
  • Right click on your project > New > Other…>XML>XML FIle> and create a XML file with the log4j.xml name.
  • Copy and paste the below xml contents in newly created XML file-

<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE log4j:configuration SYSTEM “log4j.dtd”>
<log4j:configuration xmlns:log4j=”; debug=”false”>
<appender name=”fileAppender” class=”org.apache.log4j.FileAppender”>
<param name=”Threshold” value=”INFO” />
<param name=”File” value=”logfile.log“/>
<param name=”append” value=”true”/>
<layout class=”org.apache.log4j.PatternLayout”>
<param name=”ConversionPattern” value=”%d %-5p [%c{1}] %m %n” />
<level value=”INFO”/>
<appender-ref ref=”fileAppender”/>

  • Create new class file without main method and paste below code-

public class TestCase_Logging {
public static WebDriver driver=null;
private static Logger Log = Logger.getLogger(TestCase_POF.class.getName());
public static void main(String[] args) {
System.setProperty(“”, “D:/IE_Driver/IEDriverServer.exe”);
driver = new InternetExplorerDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);“Start the application.”);


Note: Highlighted codes are important to generate the log, so don’t miss them.

  • Now run the program and go to Project root folder. System has been generated logfile.log file.