Log4j – Reporting application errors by email

This post shows how you can setup log4j to send email when errors occur in your application. log4j.properties extract:

# Root category priority: DEBUG, Appender:mail
log4j.rootCategory=debug, mail

# Configuration for receiving e-mails when ERROR messages occur.
log4j.appender.mail=org.apache.log4j.net.SMTPAppender
log4j.appender.mail.To=admin@company.com
log4j.appender.mail.From=error@application-name.com
log4j.appender.mail.SMTPHost=smtp.company.com
log4j.appender.mail.Threshold=ERROR
log4j.appender.mail.BufferSize=1
log4j.appender.mail.Subject=Application Error Occurred
log4j.appender.mail.layout=org.apache.log4j.HTMLLayout

2 Responses to “Log4j – Reporting application errors by email”

  1. Shyam Kumar Gurram Says:

    Hi,

    Thanks for the information. Does the application look into the log4j.properties file automatically when there is an exception/error or is there any configuration to be set for this. Please mail me immediately at findgsk@gmail.com

  2. Thabet Says:

    Hey,

    What if SMTP server require authentication. Where to define user name and password?

    Thanks in advanced

Leave a Reply