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

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.
 
T

Truong Hong Thi

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" />
 
J

Jon Skeet [C# MVP]

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!
 
T

Truong Hong Thi

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top