Log Execptions to Event Viewer

Topics: Enterprise Library Core, Exception Handling Application Block, General discussion, Logging Application Block
Dec 13, 2010 at 9:13 AM
Edited Dec 13, 2010 at 9:14 AM

To log exception to Event viewer currently I'm using following code sample. Code is work fine. But I need to know is there any simple way to use this than this?

public void LogException(Exception ex)


                 string error = "Error" ;






Boolean rethrow = false ;




                    // Resolve an Exception Manager instance

                    var exManager = EnterpriseLibraryContainer.Current.GetInstance<ExceptionManager >();






                    rethrow = exManager.HandleException(ex, error);







throw ex;




               if (rethrow) {





//This will truncate the stack of the exception









                  throw ex;




Dec 13, 2010 at 10:55 AM

I would say yes, this may be the simplest (assuming that your exception policy is properly configured). Though if you may want to do it in a more automated way, I suggest utilizing Policy Injection's Exception Call Handler. You can refer to the documentation for more details - http://msdn.microsoft.com/en-us/library/dd139899.aspx.

Gino Terrado
Global Technologies and Solutions
Avanade, Inc.