473,408 Members | 1,763 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

help logging events to txt file

cj
I'd like some advise on a fool proof logging system. I have a windows
app and need key events to be logged to a text file. Here are the
REQUIREMENTS I have been given--generally requirements I'm given are
non-negotiable.

--It might be hours or days between logging events or just split seconds.

--This application will be run from a network drive and the log file
will reside in the directory it is run from.

--This same exe will be run on multiple pcs at the same time and mabye
even run multiple times on the same pc. All running instances of this
app running must use the same log file.

--The log file is to be appended to.

--The log file must be able to be opened in notepad while it's being
written to. I understand opening it will only show me what's in it at
the moment it's opened.

--Trying to write to the log file must never stop the program from
running (well more than a couple of seconds). If worst come to worst
and an event can not be logged in a couple of tries don't log it.

Can anyone give me any ideas on how to do this?

I see potential problems with more than one instance of the app trying
to write at the same time and also with the file being open in notepad
when an app tries to write to it. On the up side the longest lines
being written will be exception.message text returned if an error occurs.
May 5 '06 #1
2 1079
If you try to open the file for writing from more than one program, you
will get an exception. You would have to catch and identify that
exception so that you can try to open the file again, preferably after a
short delay.

You should record the time before the first try, and/or count the number
of retries, so that the program can give up after a reasonable time
and/or number or retries.

Reading from the file while it's being written to should be no problem,
but the last record may show up partially written. I believe that the
default share mode when opening for append is read, but if it's not you
would have to specify that.

cj wrote:
I'd like some advise on a fool proof logging system. I have a windows
app and need key events to be logged to a text file. Here are the
REQUIREMENTS I have been given--generally requirements I'm given are
non-negotiable.

--It might be hours or days between logging events or just split seconds.

--This application will be run from a network drive and the log file
will reside in the directory it is run from.

--This same exe will be run on multiple pcs at the same time and mabye
even run multiple times on the same pc. All running instances of this
app running must use the same log file.

--The log file is to be appended to.

--The log file must be able to be opened in notepad while it's being
written to. I understand opening it will only show me what's in it at
the moment it's opened.

--Trying to write to the log file must never stop the program from
running (well more than a couple of seconds). If worst come to worst
and an event can not be logged in a couple of tries don't log it.

Can anyone give me any ideas on how to do this?

I see potential problems with more than one instance of the app trying
to write at the same time and also with the file being open in notepad
when an app tries to write to it. On the up side the longest lines
being written will be exception.message text returned if an error occurs.

May 5 '06 #2
I did something similar to this in an old project where upwards of 30
instances of my application had to retrieve a password from the
database then mark a bit field that the password was in use. Due to
the nature of the application, they were all starting up at roughly the
same time, so I used a COM Exe (this was in vb6) with one object that
had a GetPassword and ReleasePassword function.

I'm not 100% sure on what the .NET equivalent would be, but some kind
of remotable singleton class may do the trick.
http://msdn.microsoft.com/library/de...toremoting.asp
seems a good place to start.

This would take all the bother of synchronization and clashes out of
your windows app and let it be handled in one process.

I'll admit I haven't messed with this kind of work much in .NET so
somebody else may have better options.

john

May 5 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Tero Saarni | last post by:
I'm using Logging in my library module for producing trace log of certain events. For being more useful these log entries should be associated with the filename and line number of *users* code...
3
by: Daniel Lichtenberger | last post by:
Hi, I'm looking for a logging module to be used in a mod_python-powered website. Python 2.3's logging package seems like a good fit, however I'm not sure if it's completely safe to use it under...
4
by: Julia | last post by:
Hi, So my server is complete,I have all the code and libraries which I need but now I want to add exception management and logging capabilities I would like you to suggest a good book about...
6
by: Matt | last post by:
I have an ASP.Net page that receives batch transmissions of data from clients. I would like to add some type of logging to this application so I can review transmission issues easily. I tried...
3
by: seb | last post by:
Hi, I am writing to a file some basic information using the logging module. It is working but in the log file some line are printed several time. I had put some print debugging messages in the...
3
by: nicholas.petrella | last post by:
I am currently trying to use the python logging system as a core enterprise level logging solution for our development and production environments. The rotating file handler seems to be what I...
4
by: samwyse | last post by:
In the Python 2.5 Library Reference, section 14.5.3 (Logging to multiple destinations), an example is given of logging to both a file and the console. This is done by using logging.basicConfig()...
6
by: Larry Bates | last post by:
Every time I look at the logging module (up until now) I've given up and continue to use my home-grown logger that I've been using for years. I'm not giving up this time ;-) I find that I...
1
by: arunairs | last post by:
Hi, Using the EnterpriseLibrary 4.0, is it possible to Log the method name in the log file. I have it cofigured thus: <loggingConfiguration name="Logging Application Block"...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.