473,414 Members | 1,738 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,414 software developers and data experts.

Error tracking a windows service

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
5 1561
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

"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
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
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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jagdeesh | last post by:
Hai Colleagues, I am using Tomcat 4.1.24 and JDK 1.4.0_03 in my winXP machine. I've transferred a set of folders(containing jsp files) into tomcat's webapps directory(to /webapps/bob ,...
6
by: paul calvert | last post by:
I hope somewhere here has encountered and solved a similar problem in the past. 1) on a new Win2000 PC: installed Visual C++ 6.0 download & install single file Service Pack 5.0 2) try to...
1
by: Muddassir | last post by:
hi everybody I am writing an application for tracking files and directory changes I used FindFirstChangeNotification FindNextChangeNotification FindCloseChangeNotification...
5
by: HttpWebRequest | last post by:
I am trying to get tracking information from UPS web site without much luck. I got this working in VB 60 without any problems by using WinInet functions Here my test program. We need to get...
4
by: coosa | last post by:
Hi, I was installing SQL Server on my machine and during installation my PC freezed. It happens frequently on my machine. So i tried after restarting to install it again and since then i always...
13
by: ScottM | last post by:
I have run into a problem generating the class file via the WSDL utility. I have a WSDL file that was generated by XMLSpy and is able to be read by the Java code utility, but I get the following...
4
by: Jason Richmeier | last post by:
I am sure this has been asked at least once before but I could not find anything when searching. If I set the value of the ExitCode property to 1066 for a windows service, the text "A service...
7
by: Jason Kester | last post by:
Best I can tell, there are three basic ways you can deal with global error handling in ASP.NET. Namely: 1. Derive all your pages from a custom Page class, and override OnError() 2. Specify a...
3
by: =?Utf-8?B?R3JhaGFt?= | last post by:
I've added 2 tracking services to the wf runtime; one is the standard SqlTrackingService: trackingService = new SqlTrackingService(<trackingConnectionString>); <workflow...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.