I have two static methods that I want to use for error handling. One of which passes the exception object and the other is just used if needing to report an error which would be a text based message (string errorMessage).
The code within the two methods is pretty much the same with the exception of how the message is build up and sent to a log file. How can I refactor this so that I'm not duplicating code?
public static void ReportError(Exception exceptionRaised, string reference, string customMessage, bool sendEmail)
{
// get filename
// check if logfile exists, blah, blah
// build up message from exception, reference & custom message using string builder
// save message
// email error (if set)
}
public static void ReportError(string errorMessage, string reference, bool sendEmail)
{
// get filename
// check if logfile exists, blah, blah
// build up message from errorMessage & reference string builder
// save message
// email error (if set)
}
Thanks.