Make Selenium Easy

Log4j2 Tutorial 5 – XML Configuration File to Log Into File and Console Using Log4j2 Together

Introduction

We have already learnt the basics but important concepts of Log4j2 in series of tutorials in Log4j2 Tutorials. Now we know to create an XML configuration file to print logs in to a File and on to the console.

But sometimes it is good to print logs in to console and file as well. So now we will configure an XML document that will be capable to print logs into a file and on a console as well.

If you are thinking it will be complex then you are not correct. It will be just a combination of above mentioned two posts.

Did you know that I have started a YouTube channel as well and I need your support to make it successful. Please do watch content then comment, like, share, and obviously subscribe.

Required Dependencies

Always use the latest version of dependencies. I am using the below version of Log4j2 which is the latest at the time of writing this post.

XML configuration file with File and Console Appender

We know that to print in to console we need to use console appender and File appender to print logs in to a file. We can use both into same configuration file as below:-

Example Program

When we run above program then we can see logs printed in console and file both as below:-

Console Output

File Output

GitHub Link to clone project

Log4j2 Example Codes

You can subscribe to my YouTube channel RetargetCommon to learn from video tutorials.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.
#ThanksForReading
#HappyLearning

Find all Selenium related posts here, all API manual and automation related posts here, and find frequently asked Java Programs here.

Many other topics you can navigate through the menu.

Author: Amod Mahajan

My name is Amod Mahajan and I am an IT employee with 6+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went through so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.

Log4j2 Tutorial 5 – XML Configuration File to Log Into File and Console Using Log4j2 Together

by Amod Mahajan time to read: 2 min
0
%d bloggers like this: