Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / August 2004

Tip: Looking for answers? Try searching our database.

Renaming log file that is being read

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike Blake-Knox - 30 Aug 2004 18:00 GMT
I have a server using the .NET Framework 1.0 that writes logs onto the
end of a text file.  When the log file becomes full, it renames the log
file then creates a new file and writes logs into that file until it
too becomes full.

It is often useful to watch the text being added to the file and
display it in a window (similar to the Unix "tail -f" command). I have
found that when the server log file is opened for reading by this
viewer program, the server cannot rename the file as it receives an
error stating the file is in use by another process. It sounds quite
reasonable for this to be an error as the reading program may receive
an inconsistent view of the file.  In this case, I can adjust the
viewer to produce imperfect but usable output and would like to find a
way to avoid interference with the server's activities.

The log fle is accessed across a LAN. The viewer open a FileStream,
reads to the current end of the log file then sleeps for a while and
tries to read again. I have found that I can reduce the frequency of
the problem having the viewer close the file while it sleeps.
Unfortunately, this doesn't solve the problem as it only reduces the
chance that the viewer will have the file open when the server wants to
rename it.

I can add some tolerance of this situation to the server but this might
either reduce the severity of the problem or shift the problem to
delaying the server.

Is there any mechanism to read from the file without affecting the
server? It sounds strange that in this scenario, the reading program is
interfering with the writer rather than the other way around.

Thanks

Mike
Joshua Frank - 31 Aug 2004 16:03 GMT
If the file isn't too big, you might just avoid the whole issue by
copying the log file to another file with a different name and then
doing whatever you like with that file.

> I have a server using the .NET Framework 1.0 that writes logs onto the
> end of a text file.  When the log file becomes full, it renames the log
[quoted text clipped - 30 lines]
>
> Mike
Mike Blake-Knox - 31 Aug 2004 18:20 GMT
> If the file isn't too big, you might just avoid the whole issue by
> copying the log file to another file with a different name and then
> doing whatever you like with that file.

Thanks but Murphy's Law probably guarantees that the server will try to
roll over to a new file just as the file is being copied.

Mike

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.