问题
I want to use MDC for logging for that I'm doing
MDC.put("ReportName", "IOR_Report");
MDC.put("ReportJNDI", JNDI_NAME.getValue());
log.info("Report logger working");
And added below entry in log4j.properties and it's printing correct ReportName="My ReportName" JNDI=MYJNDI
log4j.appender.REPORTSLOG = org.apache.log4j.RollingFileAppender
log4j.appender.REPORTSLOG.layout = org.apache.log4j.PatternLayout
log4j.appender.REPORTSLOG.File = ../logs/ReportLog.log
log4j.appender.REPORTSLOG.Threshold=INFO
log4j.appender.REPORTSLOG.layout.ConversionPattern=%m - ReportName=%X{ReportName} JNDI=%X{ReportJNDI}%n
But I want to add these parameters to MDC dynamically,and so don't want to hardcode like below
ReportName=%X{ReportName} JNDI=%X{ReportJNDI}%n
It should show all MDC parameters which are added in MDC, something like below I'm expecting but it's not working, what m I missing here?
log4j.appender.REPORTSLOG.layout.ConversionPattern=%m - %X - %n
来源:https://stackoverflow.com/questions/59618615/mdc-to-log-entire-dynamic-message-irrespective-of-no-of-entries-in-mdc