本文介绍了Map中的Log4j2自定义电子邮件主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经向客户安装了一些应用程序,并且我将smtp附加程序配置为接收错误电子邮件.

I've some applications installed to my customers and I configured smtp appender to receive errors email.

不幸的是,我需要一种方法来了解从哪个客户那里收到电子邮件.

Unfortunally I need a way to understand from which customer is arriving the email.

我正在尝试在地图中设置参数,以将其显示为电子邮件的主题.我只有在启动应用程序并且数据库启动后才能设置此参数:

I'm trying to set a parameter in the map in order to show it as the subject of the email. I can set this parameter only after my app is started and the db is up:

String[] parametri = {username};
MapLookup.setMainArguments(parametri);

我的log4j2.xml是:

and my log4j2.xml is:

<SMTP name="Mailer" subject="${sys:logPath} - ${map:0}" to="${receipients}"
        from="${from}" smtpHost="${smtpHost}" smtpPort="${smtpPort}"
        smtpProtocol="${smtpProtocol}" smtpUsername="${smtpUser}"
        smtpPassword="${smtpPassword}" smtpDebug="false" bufferSize="200"
        ignoreExceptions="false">
    </SMTP>

主题是相关部分.不幸的是,该主题并未从log4j替换并保持原样.

the subject is the relevant part. Unfortunally the subject is not replaced from log4j and remains as it is.

我做错了什么?

谢谢

推荐答案

当前,SmtpAppender类(实际上是其助手SmtpManager)创建一次MimeMessage对象,并将其重新用于所有要发送的消息.消息主题仅初始化一次.读取您的配置后,查找仅完成一次.

Currently, the SmtpAppender class (actually its helper SmtpManager) creates a MimeMessage object once and reuses it for all messages to be sent. The message subject is initialized only once. The lookup is done only once when your configuration is read.

我建议您针对用例在Log4j2 Jira问题跟踪器上提出功能请求.

I suggest you raise a feature request on the Log4j2 Jira issue tracker for your use case.

这篇关于Map中的Log4j2自定义电子邮件主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 04:30