This post will help to collect full useful exception message from exception object.
This utility constructs the exception message from
1. Exception Source
2. Exception Target
3. Exception Message
and returns a concatenated string for logging. This is very useful while debugging the application.
/// <summary>
/// Get the Whole useful Exception Message from Exception object.
/// </summary>
/// <param name="ex"></param>
/// <returns></returns>
public static string GetExceptionMessage(Exception ex)
{
try
{
if (ex != null) // taking care of exception object sent in is if NULL
{
string expMessage = string.Concat("Exception Source: ", ex.Source, "\n", "Exception Target : ", ex.TargetSite, "\n", "Exception Message: ", ex.Message);
return expMessage;
}
else
{
return "";
}
}
catch (Exception e)
{
throw;
}
}
0 comments:
Post a Comment