I have a multi-threaded application using over 500 threads and I want to log certain things that go on inside these threads to a single log text file, however not all the threads can access the file at the same time so how can I do this?

The only way I can think of is to have the file as a static public resource, lock this and then access it when required. However, I don't know if this process is inefficient for this many threads.

Someone else recommended Trace Listener, but the problem with this is that it creates multiple temporary files and never seems to bring all these files together into one, which I believe it is supposed to do.

Can anyone suggest another solution?

Use log4net, it is thread-safe and can log to various different appenders including a text file (RollingFileAppender).