The Log4Net mailing list is a great source of information about using log4Net, in this forum we collect all the messages in the log4net user list and some selected threads from the developer list.
| Author |
Messages |
|
news
 |
| 11/22/2005 10:52 AM |
|
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????
|
|
|
|
|
Georg Jansen
 |
| 11/22/2005 11:50 AM |
|
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
|
|
|
|
|
Matthew Brown
 |
| 11/22/2005 2:45 PM |
|
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)
|
|
|
|
|
Christoph Walcher
 |
| 11/22/2005 3:12 PM |
|
Hi,
could you send us your code where you open the log files to be displayed in your rich text box? I guess the locking problem is not at the log4net side but in your application to display the log.
Tried to open the File using
method of File?
greets
Christoph
|
|
|
|
|
Marc Lewandowski
 |
| 11/22/2005 10:03 PM |
|
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
|
|
|
|
|
Ron Grabowski
 |
| 11/23/2005 1:52 AM |
|
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.
|
|
|
|
|
Mike Blake-Knox
 |
| 11/23/2005 2:40 PM |
|
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
|
|
|
|
|
Nicko Cadell
 |
| 12/12/2005 8:01 PM |
|
Make sure that you are opening the file for Read only and that you allow ReadWrite as the share mode, e.g. System.IO.File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
Nicko
|
|
|
|
|
|
| You are not authorized to post a reply. |
|
|
|
ActiveForums 3.7
|