1

我已将 log4j xml 配置为在我的应用程序中遇到错误时发送电子邮件,但我仍然无法收到任何邮件。如果我必须执行此配置以外的其他操作,请您建议我。以下是配置完成在电子邮件的 xml 文件中

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="true">
<appender name="XMPAYROLAppender"
        class="org.apache.log4j.DailyRollingFileAppender">
        <param name="File" value="log/XMPAYROLLogger.log" />
        <param name="datePattern" value="'.'yyyy-MM-dd" />
        <param name="append" value="true" />
        <param name="Encoding" value="UTF-8" />
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d [%t] %-5p %C{1} - %m%n" />
        </layout>
</appender>
<appender name="AdministratorEmail" class="org.apache.log4j.net.SMTPAppender">
  <param name="BufferSize" value="1024" />
  <param name="SMTPHost" value="smtp.gmail.com" />
  <param name="From" value="kiran98373@gmail.com" />
  <param name="To" value="kiran98373@gmail.com.com" />
  <param name="Subject" value="test mail" />
  <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>

<logger name="XMPAYROLLogger" additivity="true">
        <level class="org.apache.log4j.Level" value="INFO" />
        <appender-ref ref="XMPAYROLAppender" />
</logger>
</log4j:configuration>
4

1 回答 1

2

存在一个SMTPAppender类,Log4j其中通过 SMTP 为每个记录的消息发送电子邮件。

<appender name="AdministratorEmail" class="org.apache.log4j.net.SMTPAppender">
  <param name="BufferSize" value="512" />
  <param name="SMTPHost" value="some.email.host.org" />
  <param name="From" value="appname@server.com" />
  <param name="To" value="adminA@server.com,adminB@server.com" />
  <param name="SMTPUsername" value="appname@server.com" />
  <param name="SMTPPassword" value="abcdpassword" />
  <param name="SMTPDebug" value="true" /> 
  <param name="Subject" value="SomeApplication on SomeServer12" />
  <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>
于 2012-11-16T08:38:09.813 回答