I have a windows service I am trying to debug.
Is it a bad idea to add error logging in the Catch() clause?
My logging is using a database to log the errors btw.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’m not 100% clear and what you’re trying to do as you mention both debugging and logging.
Logging on the catch clause is generally a good idea if part of an overall logging approach.
if you are after debugging the service you have two option – if you can control when the code you are trying to debug from outside the service (via some external stimulus) or if you have some time before the code is executed, you can simply open the source code in VS and, as long as you’ve compiled in debug mode you can attach VS to the service process.
Then any breakpoints set in your source code would give you access to the code in debug,.
If, however, you can’t do that (for example if you need to debug the start event) you can add System.Diagnostics.Debugger.Break() to the source code which would start a debugger when this line is hit at runtime.
I usually wrap such statements in an #if #endif area controls by a compile symbol.