开发者

C# Application logger

开发者 https://www.devze.com 2023-01-27 12:07 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消