简体   繁体   English

Log4j嵌套诊断上下文NDC

[英]Log4j Nested Diagnostic Context NDC

When a user sends a request to my web application, a user session id is added to the NDC stack to be used in the log4j log files, but for some reason, when I call another method, the session id doesn't seem to be in the log calls within that method. 当用户向我的Web应用程序发送请求时,会将用户会话ID添加到NDC堆栈中,以便在log4j日志文件中使用,但是由于某种原因,当我调用另一种方法时,会话ID似乎不是在该方法内的日志调用中。 Though once that method has completed the rest of the process, still retains the session id within the log files. 尽管该方法完成了其余过程,但仍将会话ID保留在日志文件中。

I'm not too sure why this is happening and was wondering if anyone knows of why this may be or has any theories on the reason for loosing the session id? 我不太确定为什么会这样,并且想知道是否有人知道为什么这可能或是否有丢失会话ID的原因的任何理论?

Thanks for any help given. 感谢您提供的任何帮助。

NDCs are managed on a per-thread basis - that means that if you push the session ID onto the stack in one thread and then call a method in another thread your session ID won't be present. NDC是基于每个线程进行管理的-这意味着,如果您在一个线程中将会话ID推入堆栈,然后在另一个线程中调用方法,则您的会话ID将不存在。

It's hard for me to answer without the context of your code... If you post your code I could probably provide a specific answer. 没有您的代码上下文,我很难回答...如果您发布代码,我可能会提供具体答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM