C# – Running Log4Net appenders on separate thread

clog4netmultithreading

Currently, I've got my own logging system, where the log is essentially a queue, with a separate thread listening to that queue and doing all of the actual write operations. The system processes a TON of log messages, files can easily exceed 10 MB sizes in minutes, so doing the actual logging in the calling thread is not feasible.

I can't find resources online that show how threading would work in log4net, if log4net supports this kind of message passing architecture already, or other similar features to work in a threaded environment. Are there any pre-existing features that would help me?

Is this possible without creating a log4net wrapper?

Best Answer

You may want to rethink the threading approach if your log data depends on being in a specific order -- threading may interfere with that and end up posting log entries out of sequence.

You could try using MSMQ (or some other queue technology) to quickly post the log messages off to some other process which will then do the physical writes to storage. This will guarantee that messages appear in the same order they were sent.