Using log4net to write to one log file from multiple programs.

  • Thread starter Thread starter UJ
  • Start date Start date
U

UJ

Has anybody done anything with using log4net where you have multiple
programs on a single machine writing to the same log file?

TIA - J.
 
Just config so that each app does not lock the file. That affects
performance because the app has to open the file, flush the message,
and close the file immediatly.

Add following element into FileAppender/RollingFileAppender elements of
each XML config file:
<param name="LockingModel"
type="log4net.Appender.FileAppender+MinimalLock" />
 
Truong Hong Thi said:
Just config so that each app does not lock the file. That affects
performance because the app has to open the file, flush the message,
and close the file immediatly.

Add following element into FileAppender/RollingFileAppender elements of
each XML config file:
<param name="LockingModel"
type="log4net.Appender.FileAppender+MinimalLock" />

That's the correct config, but your first sentence is wrong - it *does*
lock the file. The point of MinimalLock is that it locks it, but does
so for as short a time as possible. Without *any* locking, two
different programs could corrupt each others' lock.

From the docs for MinimalLock:

<quote>
Acquires the file lock for each write
</quote>

That's quite different from not locking the file at all!
 
Thanks Jon. I understood that, just did not express it right.
I used to work on a project where a web app and a web service logged to
the same file.
It *greatly* reduced performance when we turned on debug log since we
logged many debug messages.
 
Back
Top