I have an issue with the current project I am working on. The developers have added multiple catch blocks for a try block. Each catch is logging the error and then re-throwing it. Something like this:
catch (OdbcException ex)
{
ex.Data.Add("CodeSource", MethodBase.GetCurrentMethod().Name);
ex.Data.Add("My Value", myValue);
Common.Logger.LogError(ex, "DataAccess");
throw;
}
catch (Exception ex)
{
ex.Data.Add("CodeSource", MethodBase.GetCurrentMethod().Name);
ex.Data.Add("My Value", myValue);
Common.Logger.LogError(ex, "DataAccess");
throw;
}
On top of that, the calling class may also have catch blocks doing the samething. So the log file is a mess. I have seen up to 5+ of the same message logged.
Is there anyway I can log the error just once without having to change the code everywhere? The sad thing is the project is near the end so they don't want extra time spent on doing it right. ><