Is it possible to write from 5 different processes to the same log file?
I am using Log4Net for logging, but seems like only 1 process is writing to the file, when I shut this process down, the 2nd process is writing.
I want all to write together.
How to?
If you want to write to a single file from multiple processes add the MinimalLock
as LockinModel
to your <appender>
node:
<appender .... >
......
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
......
</appender>
Beware this have some impact on the performance.
Though @Erwin's advice works in most cases, you should reconsider if a better architecture can help improve performance.
For example, Microsoft IIS server has many worker processes running, each sending log entries to IIS service process via a named pipe. And only IIS service process has the right to write to log files. In this way, worker processes do not need to lock log files, and the service process can cache entries and write them in batches.
It is very easy to follow IIS's approach and achieve good performance. without file locks.
(Updated: You can now use LogMaster4Net, which implements such an architecture based on UDP.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With