Hi
is there a way to write a logger can log the exception occurred in another program written a开发者_StackOverflowlso in c# ?Yes, but it's not easy.
If you are running the application in an AppDomain
from your current application, it's relatively easy. What you do is of that domain, you attach to the UnhandledException
event handler and register the exceptions that way.
However, I suspect that the C# application you are referring to is running in a different process. In that case, you are still using roughly the same mechanism, but it's a lot more difficult to actually get the AppDomain
. This involves managed C++ and executing a thread in a remote domain. You can look at Can I inject a thread in a remote app domain from C# and http://social.msdn.microsoft.com/Forums/en/winforms/thread/e4cfa5dd-e254-4088-8754-09dc40d4fb5b for more information about this.
Exceptions are a mechanism that exists strictly in-process, so no.
Upon an exception you could send the Exception details to another application which is responsible for logging the Exception. You could use one of a variety of Remote procedure call mechanisms such as might use web services or Windows Communication Foundation (WCF).
Here is a good example of Error Handling Extensions in WCF.
精彩评论