Hi guys!

When developing NLog (http://www.nlog-project.org) I faced an interesting problem: how to enable multiple process to append to log files in a synchronized manner.

Here are my thoughts:

1. You can achieve best performance if you keep the files open. That implies FileShare.Write when creating/opening them.

2. FileMode.Append is broken on Windows, since it only moves the file pointer once, after the file has been opened/created. This leads to race conditions when multiple processes want to append to the same file without synchronization. You get garbage in files.

What I wanted to achieve is something similar to the semantics of O_APPEND flag passed to open() function, where all append operations are atomic (http://theory.uwinnipeg.ca/gnu/glibc/libc_144.html)

On Windows I came up with the solution that uses global named mutexes to synchronize seek-and-write operation. It would be great if I could use native Unix support for appending files while running on this platform.

My question is: is FileMode.Append supposed to have O_APPEND semantics on Unix? If not, what's the best way to open file with this append semantics in mono? I've seen you have MonoIO class, but I'm not sure how it can be used. Do you have any ideas?

--
Jarek
http://blog.jkowalski.net/

_______________________________________________
Mono-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-list

Reply via email to