By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,571 Members | 1,669 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,571 IT Pros & Developers. It's quick & easy.

Error tracking a windows service

P: n/a
What is the best way that anyone has found to capture errors inside a
windows service? It's pointless to use compilation constants, as you can't
"debug" a service very easily, and you can't pass in a command line
arguement (can you?) to tell it to do something special like capture errors
to a file while it's running. Has anyone figured out any good ways to do
this type of run-time error capturing?

Basically, if I were building a standard windows app, I'd just program it so
when certain command line arguements are passed in, the compiled code would
know to output information to a file. This saves me time from having to be
on-site and step through the code line by line. Can you do something like
that with a windows service?
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Take a look at using TraceListeners and the application configuration file.
"OpticTygre" <op********@adelphia.net> wrote in message
news:Dc********************@adelphia.com...
What is the best way that anyone has found to capture errors inside a
windows service? It's pointless to use compilation constants, as you
can't "debug" a service very easily, and you can't pass in a command line
arguement (can you?) to tell it to do something special like capture
errors to a file while it's running. Has anyone figured out any good ways
to do this type of run-time error capturing?

Basically, if I were building a standard windows app, I'd just program it
so when certain command line arguements are passed in, the compiled code
would know to output information to a file. This saves me time from
having to be on-site and step through the code line by line. Can you do
something like that with a windows service?

Nov 21 '05 #2

P: n/a

"Ray Cassick (Home)" <rc************@enterprocity.com> wrote in message
news:OO**************@TK2MSFTNGP12.phx.gbl...
Take a look at using TraceListeners and the application configuration file.

"OpticTygre" <op********@adelphia.net> wrote in message
news:Dc********************@adelphia.com...
What is the best way that anyone has found to capture errors inside a
windows service? It's pointless to use compilation constants, as you
can't "debug" a service very easily, and you can't pass in a command line arguement (can you?) to tell it to do something special like capture
errors to a file while it's running. Has anyone figured out any good ways to do this type of run-time error capturing?

Basically, if I were building a standard windows app, I'd just program it so when certain command line arguements are passed in, the compiled code
would know to output information to a file. This saves me time from
having to be on-site and step through the code line by line. Can you do
something like that with a windows service?


I just started with .net, but I've been using the application event log for
a service I've been working on. Is there a reason not to?
Nov 21 '05 #3

P: n/a
OpticTygre,
I currently am using a Try/Catch around my main timer routine, within the
Catch block I log any exceptions (errors) to the Event Log
(ServiceBase.EventLog).

As Ray suggests you could also use TraceListeners.

I am considering "upgrading" my logging to either Log4Net or the Microsoft
Enterprise Library Logging Block:

http://logging.apache.org/log4net/

http://msdn.microsoft.com/library/de...tml/entlib.asp
You can pass parameters to a service, the following example demonstrates
how.

http://msdn.microsoft.com/msdnmag/is...v/default.aspx

Specifically Walkthrough item #7 & Figure 5, the args array to the
ServiceBase.OnStart method is the "parameters" to the service. You set these
parameters in the properties of the Service in Computer Management under the
Windows Control Panel.

Alternatively I simply put the settings in the app.config for the service.
Depending on the needs of the service, I would consider passing the name of
the "environment" to as a Parameter, then used this "environment" parameter
as an indexer into a custom Configuration Section in my app.config... By
"environment" I mean: unit test, system test, QA, Production...

Hope this helps
Jay
"OpticTygre" <op********@adelphia.net> wrote in message
news:Dc********************@adelphia.com...
| What is the best way that anyone has found to capture errors inside a
| windows service? It's pointless to use compilation constants, as you
can't
| "debug" a service very easily, and you can't pass in a command line
| arguement (can you?) to tell it to do something special like capture
errors
| to a file while it's running. Has anyone figured out any good ways to do
| this type of run-time error capturing?
|
| Basically, if I were building a standard windows app, I'd just program it
so
| when certain command line arguements are passed in, the compiled code
would
| know to output information to a file. This saves me time from having to
be
| on-site and step through the code line by line. Can you do something like
| that with a windows service?
|
|
Nov 21 '05 #4

P: n/a
The event log is fine for things that you can easily document (stopping,
starting, exceptions during critical areas, etc...) but for debug style
traces nothing beats a good old fashioned, well formatted text file.

I have seen sooo many service type apps that try to use the vent log for
debug type tracing. Makes it a real pain in the butt to actual trace code
that way, and besides, you can really fill up someone's log file if you're
not careful.

"NetworkElf" <su**@somedomain.com> wrote in message
news:eO**************@TK2MSFTNGP15.phx.gbl...

"Ray Cassick (Home)" <rc************@enterprocity.com> wrote in message
news:OO**************@TK2MSFTNGP12.phx.gbl...
Take a look at using TraceListeners and the application configuration

file.


"OpticTygre" <op********@adelphia.net> wrote in message
news:Dc********************@adelphia.com...
> What is the best way that anyone has found to capture errors inside a
> windows service? It's pointless to use compilation constants, as you
> can't "debug" a service very easily, and you can't pass in a command line > arguement (can you?) to tell it to do something special like capture
> errors to a file while it's running. Has anyone figured out any good ways > to do this type of run-time error capturing?
>
> Basically, if I were building a standard windows app, I'd just program it > so when certain command line arguements are passed in, the compiled
> code
> would know to output information to a file. This saves me time from
> having to be on-site and step through the code line by line. Can you
> do
> something like that with a windows service?


I just started with .net, but I've been using the application event log
for
a service I've been working on. Is there a reason not to?

Nov 21 '05 #5

P: n/a

"Ray Cassick (Home)" <rc************@enterprocity.com> wrote in message
news:uU**************@TK2MSFTNGP12.phx.gbl...
I have seen sooo many service type apps that try to use the vent log for
debug type tracing. Makes it a real pain in the butt to actual trace code
that way, and besides, you can really fill up someone's log file if you're
not careful.


Programming is my second hat (that's why I'm not very good at it). My first
hat is being an engineer. As you probably know, we know everything. I would
never fill up an event log... :p Thanks for the info.
Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.