log4j2无法向电子邮件发送错误通知

时间:2015-08-28 06:30:40

标签: java xml log4j log4j2 smtpappender

我目前正在创建一个Java应用程序。我想在我的应用程序出错时向我的Gmail帐户发送电子邮件通知。我在下面的log4j2.xml文件中有一部分。但是,当我尝试运行我的应用程序时,应用程序打印出来

2015-08-28 14:16:51,671 ERROR Unable to locate appender Email for logger 

我不确定为什么它不起作用。帮助将不胜感激

这是我的log4j2.xml文件的一部分。

<appender name= "Email" class="org.apache.log4j.net.SMTPAppender">

        <param name = "BufferSize" value = "50"/>
        <param name = "SMTPHost" value = "smtp.gmail.com"/>
        <param name = "SMTPort" value = "465"/>
        <param name = "SMTPUsername" value ="myemail@gmail.com"/>
        <param name = "SMTPPassword" value ="mypassword"/>
        <param name = "From" value="myemail@gmail.com"/>
        <param name = "To" value="myemail@gmail.com"/>
        <param name = "Subject" value="Testing Log4j mail notification"/>
        <layout class = "org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="[%d{ISO8601}]%n%n%-5p%n%n%c%n%n%m%n%n" />
        </layout>

        <filter class="org.apache.log4j.varia.LevelRangeFilter">
            <param name="LevelMin" value="error"/>
            <param name="LevelMax" value="fatal"/>
        </filter>

    </appender>

这是我的主要课程

package com.testcase;

import org.apache.logging.log4j.Logger ;
import org.apache.logging.log4j.LogManager;


public class log4jDemo {

    protected static Logger logger = LogManager.getLogger(log4jDemo.class);

    public static void main (String [] args){


    logger.trace("trace message");
    logger.warn("warn message");
    logger.error("Error message, a very long error message");

    }
}

0 个答案:

没有答案