Listing 1: Writing Additional Details to a Text File to Be Added to Windows Event Logs
public static void RaiseTheAlarm(string errPath, string LoadName, Boolean writeToEventLog, Exception ex)
{
//irrelevant code removed
StreamWriter ErrorWrite = new StreamWriter(logPath.ToString() );
ErrorWrite.WriteLine("There has been an error in the load of " + LoadName);
ErrorWrite.WriteLine("Exception Message");
ErrorWrite.WriteLine(ex.Message);
string errMess = ex.Message;
if (ex.InnerException == null)
{
if (errMess.Contains("An unknown error has occurred. Please contact the application administrator for further information."))
{
ErrorWrite.WriteLine("This error typically appears when there is a failure with a call to a web service. Please chack the appropriate WCF service for errors.");
}
}
else
{
ErrorWrite.WriteLine("Inner exception: ");
ErrorWrite.WriteLine(ex.InnerException.Message);
if ( ex.InnerException.InnerException != null)
{
ErrorWrite.WriteLine("Inner exception: ");
ErrorWrite.WriteLine(ex.InnerException.InnerException.Message);
}
}
ErrorWrite.Flush();
ErrorWrite.Close();
//irrelevant code removed
}