Tuesday, 21 July 2015

Log file generating and posting data

package testNG;

import java.io.IOException;
import org.apache.log4j.Appender;
import org.apache.log4j.FileAppender;
import org.apache.log4j.Logger;
import org.apache.log4j.SimpleLayout;
import org.testng.annotations.Test;


public class AssertionsTest {

   
    @Test
    public void assertionTest(){
       
         Logger logger = Logger.getLogger("MyLog");
            Appender fh = null;
            try {
                fh = new FileAppender(new SimpleLayout(), "C:\\Users\\Youtility\\Desktop\\MyLogFile.log");
                logger.addAppender(fh);
                fh.setLayout(new SimpleLayout());
                logger.info("My first log");
            } catch (SecurityException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            logger.info("Hi How r u?");
       
        System.out.println("Completed.");
    }
}

No comments:

Post a Comment