If the user removes the logging configuration from App.Config, an ActivationException is raised when Logger.Write("test") is called.
What is the best way to test for this without raising an exception?
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.
As I mentioned in a comment, I don’t think there is a foolproof way to determine if an exception will be raised. I’m not sure about the specific details of your application but one approach would be to attempt to log a message at application startup. E.g. “Application Starting.” If it succeeds, great. If it throws an exception then catch the exception and configure Enterprise Library using the fluent API with a default configuration. Then you can log a message indicating the application startup logging failure.
After application startup Enterprise Library should most probably be properly configured and subsequent Logger.Write’s should succeed.