I hope you can help me.
I have a web service that needs to log transactions. Since there are many hits, the log statements appears disjoint/fragmented in the log file.
I've considered passing a StringBuilder instance through-out the layers and appending the statements to this instance, then I log its contents once at the very end (finally clause in the main controller) before returning a response to the client. This seems unnecessary and I'm sure there's a cleaner way to do it with Log4J.
Can anyone shed light on the issue?
Thanks
the good things is that you are using Log4j. The library itself implements the concept of nested diagnostic context (org.apache.log4j.NDC
) and mapped diagnostic context (org.apache.log4j.MDC
). I reckon you should definitely have a look at both, because those allows you to build some sort of the context that you can use in your log output layout.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With