Hi,
I want to send an email using Log4j whenever there is an error .
<!-- EMail events to an administrator -->
<appender name="SMTP" class="org.apache.log4j.net.SMTPAppender">
<param name="Threshold" value="ERROR"/>
<param name="To" value="xxx@test.com"/>
<param name="From" value="yyy@test.com"/>
<param name="Subject" value="JBoss Sever Errors"/>
<param name="SMTPHost" value="xxxxx"/>
<param name="BufferSize" value="10"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{ABSOLUTE},%c{1}] %m%n"/>
</layout>
</appender>
I configured the above parameters with appropriate values. Now how do I
send an email when there is an error.I am using jboss server.
Here is the code I am trying to test to send an email..
import org.apache.log4j.*;
public class Log4jExample
{
private static final Logger log =
Logger.getLogger("Log4jExample.class");
public static void main(String[] args)
{
try
{
int i = Integer.parseInt("Hello world");
}
catch (java.lang.Exception ex)
{
java.io.StringWriter strWriter = new java.io.StringWriter();
java.io.PrintWriter writer = new
java.io.PrintWriter(strWriter);
String str = ex.getMessage();
ex.printStackTrace(writer);
log.info(strWriter.toString(), ex);
}
}
}
The above code is not sending an email. Do I need any other settings?
Thanks.
I want to send an email using Log4j whenever there is an error .
<!-- EMail events to an administrator -->
<appender name="SMTP" class="org.apache.log4j.net.SMTPAppender">
<param name="Threshold" value="ERROR"/>
<param name="To" value="xxx@test.com"/>
<param name="From" value="yyy@test.com"/>
<param name="Subject" value="JBoss Sever Errors"/>
<param name="SMTPHost" value="xxxxx"/>
<param name="BufferSize" value="10"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{ABSOLUTE},%c{1}] %m%n"/>
</layout>
</appender>
I configured the above parameters with appropriate values. Now how do I
send an email when there is an error.I am using jboss server.
Here is the code I am trying to test to send an email..
import org.apache.log4j.*;
public class Log4jExample
{
private static final Logger log =
Logger.getLogger("Log4jExample.class");
public static void main(String[] args)
{
try
{
int i = Integer.parseInt("Hello world");
}
catch (java.lang.Exception ex)
{
java.io.StringWriter strWriter = new java.io.StringWriter();
java.io.PrintWriter writer = new
java.io.PrintWriter(strWriter);
String str = ex.getMessage();
ex.printStackTrace(writer);
log.info(strWriter.toString(), ex);
}
}
}
The above code is not sending an email. Do I need any other settings?
Thanks.