You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by Sankalp <sa...@proteans.com> on 2005/11/22 10:52:56 UTC

Log4Net file locking

Hi,
We wish to port our .NET windows application logging to Log4Net but are facing a
problem. Our application dispays the log file in a rich text box so that the
user can debug himself what all is happening in the application. We plan to user
RollingFileAppender so that logs can remain for certain period pf time.
However, there is some problem here. When we try reading the log file and
display it in the rich text box, then it says that the file is in use and cant
be accessed. Log4Net is putting a lock on the file. I tried changing the locking
level to Minimal Lock using a file Appender but even that didnt help as as soon
as the log is written, we simultaneoulsy display it in the rich text box.
Pointers any one????


Re: Log4Net file locking

Posted by Mike Blake-Knox <mi...@gmail.com>.
I'd suggest that you change the program that's displaying the log file so
that it uses FileAccess.ReadWrite AND FileShare.ReadWrite when opening the
file. Otherwise, you won't be able to open the file as it already has a
writer.

This generally works fine with the RollingFileAppender but note that if you
use RollingFileAppender options that cause the file to be renamed, the
RollingFileAppender is automatically entered in the "can't rename the file
because someone else has it open lottery". (If you're using .NET 2.0,
there's a chance that adding Delete to FileShare in your program will
resolve this). Alternatively, using a FileSystemWatcher in your reading
program so that the file isn't open all the time might help.

Mike

On 11/22/05, Sankalp <sa...@proteans.com> wrote:
>
> Hi,
> We wish to port our .NET windows application logging to Log4Net but are
> facing a
> problem. Our application dispays the log file in a rich text box so that
> the
> user can debug himself what all is happening in the application. We plan
> to user
> RollingFileAppender so that logs can remain for certain period pf time.
> However, there is some problem here. When we try reading the log file and
> display it in the rich text box, then it says that the file is in use and
> cant
> be accessed. Log4Net is putting a lock on the file. I tried changing the
> locking
> level to Minimal Lock using a file Appender but even that didnt help as as
> soon
> as the log is written, we simultaneoulsy display it in the rich text box.
> Pointers any one????
>
>


--
Mike Blake-Knox

Re: Log4Net file locking

Posted by Ron Grabowski <ro...@yahoo.com>.
I wonder if it would be worthwhile to make a ModestLock that locks the
file for a few seconds after the last log in anticipation of another
log message. When recording a lot of messages you'd benefit from having
an exclusive lock during a lot of messages then when the system has
slowed down some (i.e. no messages in 2+ seconds) it releases the lock.
Maybe that time period would be need to be tweaked or configurable.

--- Matthew Brown <oc...@gmail.com> wrote:

> Just a warning though, in my experience with MinimalLock, it slows
> down
> execution of the program significantly (as log4net has to lock the
> file,
> write it, unlock it, repeat)
> 
> On 11/22/05, Georg Jansen <Ge...@faktnet.com> wrote:
> >
> > Hi,
> >
> > You can try to change the lock level:
> >
> > <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
> >
> > (This must be inserted in the config file in the section where you
> define
> > the RollingFileAppender).
> >
> >
> > Best regards
> > Georg
> > http://www.l4ndash.com - Log4Net Dashboard / Log Viewer
> >
> > -----Original Message-----
> > From: news [mailto:news@sea.gmane.org] On Behalf Of Sankalp
> > Sent: 22. november 2005 10:53
> > To: log4net-user@logging.apache.org
> > Subject: Log4Net file locking
> >
> > Hi,
> > We wish to port our .NET windows application logging to Log4Net but
> are
> > facing a
> > problem. Our application dispays the log file in a rich text box so
> that
> > the
> > user can debug himself what all is happening in the application. We
> plan
> > to
> > user
> > RollingFileAppender so that logs can remain for certain period pf
> time.
> > However, there is some problem here. When we try reading the log
> file and
> > display it in the rich text box, then it says that the file is in
> use and
> > cant
> > be accessed. Log4Net is putting a lock on the file. I tried
> changing the
> > locking
> > level to Minimal Lock using a file Appender but even that didnt
> help as as
> > soon
> > as the log is written, we simultaneoulsy display it in the rich
> text box.
> > Pointers any one????
> >
> >
> >
> >
> 


Re: Log4Net file locking

Posted by Matthew Brown <oc...@gmail.com>.
Just a warning though, in my experience with MinimalLock, it slows down
execution of the program significantly (as log4net has to lock the file,
write it, unlock it, repeat)

On 11/22/05, Georg Jansen <Ge...@faktnet.com> wrote:
>
> Hi,
>
> You can try to change the lock level:
>
> <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
>
> (This must be inserted in the config file in the section where you define
> the RollingFileAppender).
>
>
> Best regards
> Georg
> http://www.l4ndash.com - Log4Net Dashboard / Log Viewer
>
> -----Original Message-----
> From: news [mailto:news@sea.gmane.org] On Behalf Of Sankalp
> Sent: 22. november 2005 10:53
> To: log4net-user@logging.apache.org
> Subject: Log4Net file locking
>
> Hi,
> We wish to port our .NET windows application logging to Log4Net but are
> facing a
> problem. Our application dispays the log file in a rich text box so that
> the
> user can debug himself what all is happening in the application. We plan
> to
> user
> RollingFileAppender so that logs can remain for certain period pf time.
> However, there is some problem here. When we try reading the log file and
> display it in the rich text box, then it says that the file is in use and
> cant
> be accessed. Log4Net is putting a lock on the file. I tried changing the
> locking
> level to Minimal Lock using a file Appender but even that didnt help as as
> soon
> as the log is written, we simultaneoulsy display it in the rich text box.
> Pointers any one????
>
>
>
>

RE: Log4Net file locking

Posted by Georg Jansen <Ge...@FaktNet.com>.
Hi,

You can try to change the lock level:
 
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />

(This must be inserted in the config file in the section where you define
the RollingFileAppender).


Best regards
Georg
http://www.l4ndash.com - Log4Net Dashboard / Log Viewer

-----Original Message-----
From: news [mailto:news@sea.gmane.org] On Behalf Of Sankalp
Sent: 22. november 2005 10:53
To: log4net-user@logging.apache.org
Subject: Log4Net file locking

Hi,
We wish to port our .NET windows application logging to Log4Net but are
facing a
problem. Our application dispays the log file in a rich text box so that the
user can debug himself what all is happening in the application. We plan to
user
RollingFileAppender so that logs can remain for certain period pf time.
However, there is some problem here. When we try reading the log file and
display it in the rich text box, then it says that the file is in use and
cant
be accessed. Log4Net is putting a lock on the file. I tried changing the
locking
level to Minimal Lock using a file Appender but even that didnt help as as
soon
as the log is written, we simultaneoulsy display it in the rich text box.
Pointers any one????




RE: Log4Net file locking

Posted by Marc Lewandowski <ma...@telebill.com>.
Just a thought, since it seems like what you are attempting is a real-time
logging scenario, why not use a different appender more suited to the task?
You could retain the rolling-file appender, but for the RichTextBox you
could display the contents of a console appender (if it is in the same
process) or a remoting or UDP appender (if logging and viewing are in
separate processes).

Another thought: if you do want to be able to view the file, you should just
be able to open the file in a read-only fashion without using the (somewhat
expensive) minimal lock option.  I've noticed that I can open log files in
Notepad while they are still being written to by L4N.

-Marc

-----Original Message-----
From: news [mailto:news@sea.gmane.org] On Behalf Of Sankalp
Sent: Tuesday, November 22, 2005 4:53 AM
To: log4net-user@logging.apache.org
Subject: Log4Net file locking


Hi,
We wish to port our .NET windows application logging to Log4Net but are
facing a problem. Our application dispays the log file in a rich text box so
that the user can debug himself what all is happening in the application. We
plan to user RollingFileAppender so that logs can remain for certain period
pf time. However, there is some problem here. When we try reading the log
file and display it in the rich text box, then it says that the file is in
use and cant be accessed. Log4Net is putting a lock on the file. I tried
changing the locking level to Minimal Lock using a file Appender but even
that didnt help as as soon as the log is written, we simultaneoulsy display
it in the rich text box. Pointers any one????