Open notepad

  • Thread starter Thread starter Daniel
  • Start date Start date
D

Daniel

Hi

I have a server programme and it writes any errors quietly to a logfile so
that the server keeps running and only dies on a critical problem. I'd like
to have a menu item saying View Log that i can click and it will open my
logfile in notepad (any better alternative methods for viewing a log please
let me know).

Does anyone know how to do this? Or would it be easier to make my own form
and just open the file myself and write the contents to the form?

Thanks in advance
 
Well, personally I would develop this as a service, but that is
by-the-by. However, for logging, have you considered the event-log?
This is a well understood, well supported framework that supports
remote monitoring etc. You can create your own logs to segregate your
data from the OS's...

And from a UI you can either start the eventvwr.exe (a shim to MMC
these days), or you can query the event-log via the managed API to
display it.

Marc
 
Daniel said:
I have a server programme and it writes any errors quietly to a logfile so
that the server keeps running and only dies on a critical problem. I'd like
to have a menu item saying View Log that i can click and it will open my
logfile in notepad (any better alternative methods for viewing a log please
let me know).

Take a look at the System.Diagnostics.ProcessStartInfo class.

Personally I'd have it use the name of the log as the process filename,
rather than "notepad.exe <logfile.txt>" because that way it should use
the user's registered application associated with .txt files if they've
changed this, rather than forcing them to use notepad.

http://msdn2.microsoft.com/en-us/library/system.diagnostics.processstartinfo(VS.80).aspx
 
I considered that yes but it hought its such a simple need at the moment.
Maybe you are right thats best i just thought possibly a bit of overkill to
do that. I like the idea of having my log separate from anything else
getting logged by event log.
 
The following code should work opening the logfile with the application
that the client machine registered with.

{
System.Diagnostics.ProcessStartInfo pi = new
System.Diagnostics.ProcessStartInfo(@"C:\log.txt"); // log file file
path
System.Diagnostics.Process.Start(pi);
}

and for logging the famous log4net is available.

Thanks
-Srinivas.
 
Simpler (given no other properties used):

System.Diagnostics.Process.Start(@"C:\log.txt"");

Marc
 
Have a look at NLog as well.
If you are after simplicity, then it is the simplest API to use in my
opinion.

My personal preference is to log to a database table so that the user can do
various searches across the log as well as sorting.

--
With Regards
Shailen Sukul
..Net Architect
(MCPD: Ent Apps, MCSD.Net MCSD MCAD)
Ashlen Consulting Services
http://www.ashlen.net.au
 
Back
Top