开发者

Log4j SMTPappender with HTML mail

开发者 https://www.devze.com 2023-01-15 10:11 出处:网络
I would like to use log4j and send email in HTML format (Using 开发者_如何学GoSMTP Appender). Is it possible in log4j out of the box.

I would like to use log4j and send email in HTML format (Using 开发者_如何学GoSMTP Appender). Is it possible in log4j out of the box.

If so please point me to right examples


Logback provides a Layout that formats the logs as HTML. Combining that with an SMTPAppender would send email in HTML format.

http://logback.qos.ch/manual/layouts.html#ClassicHTMLLayout

Direct quote from the page:

The HTMLLayout is often used in conjunction with SMTPAppender so that outgoing email is pleasantly formatted in HTML.

You could even take the source code and modify it, pretty easily, to suit your needs.

http://logback.qos.ch/xref/ch/qos/logback/classic/html/HTMLLayout.html


They provide the following code to initilaize the appender:

 <appender name="SMTP" class="ch.qos.logback.classic.net.SMTPAppender">
    <layout class="ch.qos.logback.classic.html.HTMLLayout">
      <pattern>%relative%thread%mdc%level%class%msg</pattern>
    </layout>
    <From>sender.email@domain.net</From>
    <SMTPHost>mail.domain.net</SMTPHost>
    <Subject>LastEvent: %class - %msg </Subject>
    <To>destination.email@domain.net</To> 
  </appender>


I hope that helps in some way,

-gMale

0

精彩评论

暂无评论...
验证码 换一张
取 消