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

Global exception handler for windows service application

I would like my windows service application to log all exceptions that
occur, on any of its threads, to the windows event log. Is this possible? If
so, can anyone give me an example of the necessary code?
Nov 20 '05 #1
7 6760
The AppDomain class has an UnhandledException event. Try to handle that and
put the logging code in there.

"Adam J. Schaff" <as*****@cascocdev.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I would like my windows service application to log all exceptions that
occur, on any of its threads, to the windows event log. Is this possible? If so, can anyone give me an example of the necessary code?

Nov 20 '05 #2
I have added a handler for AppDomain.CurrentDomain.UnhandledException to
both the Shared Sub Main and the OnStart method, with no luck. In both
cases, I threw an exception immediately after adding the handler, but my
handler procedure never gets called.

Anyone have any other ideas?

"Marina" <so*****@nospam.com> wrote in message
news:eK**************@TK2MSFTNGP10.phx.gbl...
The AppDomain class has an UnhandledException event. Try to handle that and put the logging code in there.

"Adam J. Schaff" <as*****@cascocdev.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I would like my windows service application to log all exceptions that
occur, on any of its threads, to the windows event log. Is this
possible? If
so, can anyone give me an example of the necessary code?


Nov 20 '05 #3
Check out the WriteEntry method to write to the event log.

http://msdn.microsoft.com/library/de...classtopic.asp

writing all exceptions that occur to the event log is not necessarily the best route. (you can if thats what you want)

log application (service) start, end, major warnings and important messages etc. in the event log
i think you should log most other exceptions and/or log messages to a user configurable logfile, since they might tend to grow larger.
Nov 20 '05 #4
Thanks for your input. I already know how to write to the event log. The
piece of the puzzle that eludes me is how do I intercept unhandled
exceptions in a windows service since they seem to just kill the thread (but
not the service) without my ever having a chance to handle them.

In other words, I can't find anywhere to place the WriteEntry code that will
get called when an exception occurs. :(

"tMan" <an*******@discussions.microsoft.com> wrote in message
news:EA**********************************@microsof t.com...
Check out the WriteEntry method to write to the event log.

http://msdn.microsoft.com/library/de...classtopic.asp
writing all exceptions that occur to the event log is not necessarily the best route. (you can if thats what you want)
log application (service) start, end, major warnings and important messages etc. in the event log i think you should log most other exceptions and/or log messages to a user

configurable logfile, since they might tend to grow larger.
Nov 20 '05 #5
On further investigation, it's only exceptions occurring in threads other
than the main one that are not getting caught by my unhandled exception
handler. Does anyone know how I can get at those exceptions?

"Adam J. Schaff" <as*****@cascocdev.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I would like my windows service application to log all exceptions that
occur, on any of its threads, to the windows event log. Is this possible? If so, can anyone give me an example of the necessary code?

Nov 20 '05 #6
My problem is more mundane than I realized. I'm subclassing a class in a 3rd
party component and I now believe they are handling the exceptions from my
subclass and throwing them away before the appdomain unhandledexception
event is triggered. It looks like it's good ol' try..catch for me in the
subclass.

"Adam J. Schaff" <as*****@cascocdev.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I would like my windows service application to log all exceptions that
occur, on any of its threads, to the windows event log. Is this possible? If so, can anyone give me an example of the necessary code?

Nov 20 '05 #8

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

Similar topics

0
by: Derek Wolf | last post by:
I am having some difficulties implementing an UnHandledException handler for the AppDomain.UnhandledException event in a windows service for unhandled exceptions that occur on a System.Timers.Timer...
2
by: MatthewRoberts | last post by:
Howdy All, I have a Windows Service that often stops in its tracks with no exception and no explanation on our QA system. During testing on the development machine, it can handle any workload,...
2
by: thechaosengine | last post by:
Hi everyone, Is there anyway to create some sort of catch-all in windows forms applications that could ensure that no unexpected exceptions bring down an application? For example, perhaps...
2
by: VM | last post by:
Is it possible to intercept all exception errors into one Try...Catch? I've tried wrapping Application.Run() in a Try...Catch, but it doesn't seem to work all the time. Thanks.
9
by: Claudio Di Flumeri | last post by:
Hello all, I've added a global exception handler to my application in this way: Sub Main() AddHandler Application.ThreadException, AddressOf ThreadException AddHandler...
3
by: kingski | last post by:
I have a web site created with ASP.NET 1.1. availability Global.asax: protected void Application_PreRequestHandlerExecute(Object sender, EventArgs e)
2
by: yeghia \(sosy\) | last post by:
Hi Guys I have two questions. 1. Is there a way to set a handler to .NET application so that in case of not caught exception my handler is called before application shutdown. I want to send an...
3
by: Simon Harvey | last post by:
Hi all, What is the best way to catch any and all exceptions when creating a windows service application? Is there some sort of global exception event I can use, or is it possible to surround...
6
by: Steve | last post by:
Hi All I have a windows forms Application (SAM) in vb.net 2008 using .net framework V2 One and only one customer out of 30 customers is getting errors daily where they have to close and...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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...

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.