We are using the MDC (mapped diagnostic contexts) to log certain context information from a server in a multiple client environment Additionally, serious error events are mailed using the SMTP appender. We notice that in the generated mails, often the logged events from the MDC are not correct, they contain log info from different client sessions. Looking at the SMTPAppender source, it appears to us that the appender is not using the MDC at all, but only the NDC. We created our own SMTPAppender and override the append method. we have added the following statements: event.getMDCCopy(); super.append(event); This seems to do the trick (even though it is said that getMDCCopy(); creates a shallow copy!) The problem appears in the following environment: log4J version 1.2.6 (but also tried 1.2.7) with Weblogic6.1 SP4 on Unix(HP) and WinNT, consequently we use the weblogic JVM (corresponding with JDK1.3)
Committed in rev 439010 and 439011 (trunk and 1.2 branch) respectively. SMTPAppender works similarly to AsyncAppender where the event may be handled by another thread (on call to triggering message) so all thread-related state must be captured during the initial processing. event.getMDCCopy() which is called in AsyncAppender was not called in SMTPAppender.