public void DispatchExceptionLogMessage(ExceptionLogMessage entry) { try { var error = new Log { Username = entry.Username, Timestamp = entry.Timestamp, LoggingLevel = (int) LoggingLevels.Exception, Message = entry.Message ?? "unknown", MethodName = entry.MethodName ?? "unknown", Source = entry.Source ?? "unknown", StackTrace = (entry.StackTrace ?? "unknown").Replace(@"\r\n", " -- ") }; db.Logs.InsertOnSubmit(error); db.SubmitChanges(); } catch (Exception ex) { // GOT NOTHING TO DO HERE Console.WriteLine(ex.Message); } }
public static void LogException(string user, Exception ex, bool sendEmail) { ExceptionMessageAgent agent = null; var msg = new ExceptionLogMessage(ex) { Username = user }; try { Console.WriteLine(msg.ToString()); agent = new ExceptionMessageAgent(); agent.DispatchExceptionLogMessage(msg); if (ConfigItems.SendErrorEmails && sendEmail) { var email = new ExceptionEmail { Ex = ex, Username = user }; SendEmail(ConfigItems.ErrorEmailAddress, "AirtimeBilling Error", email, false); } // After send of initial exception email, log the other exceptions if (ex is SqlException) { var sex = ex as SqlException; foreach (SqlError error in sex.Errors) { var sqlExMsg = new ExceptionLogMessage(sex) { Message = error.Message, StackTrace = string.Format("server={0}, Procedure={1}", error.Server, error.Procedure), Username = user }; Console.WriteLine(msg.ToString()); agent.DispatchExceptionLogMessage(sqlExMsg); } } } catch (Exception ex1) { // Can't do anything here or we'll recurse to death! Console.WriteLine(ex1.Message); } finally { if (agent != null) agent.Close(); } }