Question

I have a WCF service where in I use Log4Net for logging information to Sql Server database. I use Log4Net's GlobalContext to log some extra information, like Transaction Name, Status, Message, and few other stuff. Some of the important transactions within this system are Read, Write and Login.

The log should look like:

  • "Read" -------- "Success" -------- "Read xxx customer data"
  • "Write" -------- "Success" -------- "Written xxx customer's data"
  • "Login" -------- "Failure" -------- "User session already exists."

Everything works fine when I run my normal tests - the logs are written to the database perfectly. However, recently I did a load test by using JMeter. The above mentioned three transactions were tested in 100 concurrent threads for 3 minutes. When I checked the DB logs, I found that some of the information were logged incorrectly.

Ex:

  • "Read" -------- "Success" -------- "User session already exists."
  • "Write" -------- "Success" -------- "Read xxx customer data"

Is this an issue with Log4Net GlobalContext not being thread safe? I tried using ThreadContext instead of GlobalContext, but looks like lots of information were not logged.

Was it helpful?

Solution

LogicalThreadContext did the trick for me!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top