如何使用slf4j / log4j2发送电子邮件通知? [英] How to send email notifications with slf4j / log4j2?

查看:166
本文介绍了如何使用slf4j / log4j2发送电子邮件通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经研究了其他类似的问题并且已经做了一些谷歌搜索来找到我的答案,但我的问题仍然没有答案。我仍然不熟悉其中一些是如何工作的,所以请耐心等待。

I've looked into other questions that are similar and have done some googling to find my answer but my question is still unanswered. I'm still unfamiliar with how some of this works, so bear with me.

我们的maven pom.xml正在使用slf4j依赖:

Our maven pom.xml is using the slf4j dependency:

和我们的log4j2.xml文件如下所示:

and our log4j2.xml file looks like this:

我只将其添加到上面的log4j2.xml文件< SMTP name =Mail...> < / SMTP> 并在我添加的文件中降低< logger name =com.path.class1...> < appender ...> < / logger>

I only added this to the above log4j2.xml file <SMTP name="Mail" ...> </SMTP> and lower down in the file i added <logger name="com.path.class1" ...> <appender ...> </logger>

但出于某种原因,当我调用log.error(错误消息)时,我的电子邮件不是发给我。我知道smtp主机可以工作,因为它在.NET服务中使用。 smtp服务器不需要任何凭据即可使用它。我知道我的log.error调用是在正确的目录和文件路径中。我已经尝试设置端口,但这没有任何区别。我如何让电子邮件通知工作?

But for some reason, when I call log.error("error message"), my email isn't sent to me. I know the smtp host works because it is used in a .NET service. The smtp server does not require any credentials to use it. I know that my log.error call is in the correct directory and file path. I've tried setting the port, but that didn't make any difference. How do i go about getting the email notifications to work?

我甚至尝试过mailAppender,但这也不起作用:

I even tried the mailAppender, but that didn't work either:

推荐答案

所以我终于是能够使SMTP通知工作。这是使其工作的log4j2.xml文件:

So i finally was able to get SMTP notifications to work. This is the log4j2.xml file that made it work:

这篇关于如何使用slf4j / log4j2发送电子邮件通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆