I am having issues with multiple threads in a c# application trying to read and/or write to a log file. Occasionally an exception is thrown, and I am suspecting this is due to collisions. Is there a good way to guarantee exclusive access for each thread when it opens the files?
Share
Locking is probably the more suitable way here. If performance is critical, you could resort to some kind of queuing of the log messages with e.g. a
ConcurrentQueue<T>, which should be quite optimized for concurrent read/write, together with a producer consumer pattern.