Exceptions can be of any type. Suppose you want to log only SQL Exceptions. This is can also be done.
First step of Exception handling and Logging, is creating of Exception Handling Application block.
Now right click "LogPolicy" -> New -> ExceptionType.
It will display a list of exception which are to be handled by "LogPolicy".
I have choosen "Exception", its obvious that it will handle any exception.
Now right click "Exception" -> New -> Logging Handler
Here I choose the TextExceptionFormatter
Now click "Log Category" -> U will a drop down which points to the Logging Application Block -> Category Sources-> General - Select it
Using it Code:
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;
using Microsoft.Practices.EnterpriseLibrary.Logging;
try
{
}
catch (Exception ex)
{
bool rethrow = ExceptionPolicy.HandleException(ex, "LogPolicy");
if (rethrow)
throw;
return;
}