我将Log4J配置为在发生异常时向我发送电子邮件,但是当它发生时,我收到了大量电子邮件(如10),而不是向我发送一封电子邮件。
我不知道出了什么问题。
这是我的配置:
<configuration>
<conversionRule conversionWord="coloredLevel" converterClass="play.api.Logger$ColoredLevel" />
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>${application.home}/logs/application.log</file>
<encoder>
<pattern>%date - [%level] - from %logger in %thread %n%message%n%xException%n</pattern>
</encoder>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%coloredLevel %logger{15} - %message%n%xException{5}</pattern>
</encoder>
</appender>
<appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
<smtpHost>smtp.mandrillapp.com</smtpHost>
<smtpPort>587</smtpPort>
<SSL>true</SSL>
<username>my@email.com</username>
<password>******</password>
<to>me@account.com</to>
<from>support@app.com</from>
<subject>[App error] - %ex{short}</subject>
<cyclicBufferTracker class="ch.qos.logback.core.spi.CyclicBufferTracker">
<bufferSize>5</bufferSize>
</cyclicBufferTracker>
<layout class="ch.qos.logback.classic.html.HTMLLayout">
<pattern>%ex{full}</pattern>
</layout>
<!--<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%d%n%throwable{short}%n%n%xEx{full}</pattern>
</layout>-->
</appender>
<logger name="play" level="INFO" />
<logger name="application" level="INFO"/>
<root level="ERROR">
<appender-ref ref="STDOUT" />
<appender-ref ref="EMAIL" />
</root>
<root level="DEBUG">
<appender-ref ref="FILE" />
</root>
</configuration>