public static void LogException(Exception e, Models.Fault Fault) { try { string eInnerString = "No InnerException"; if (e.InnerException != null) { eInnerString = e.InnerException.ToString(); } using (var db = new Models.Database()) { var exception = new Models.ExceptionLog(); exception.Data = e.Data.ToString(); exception.Fault = Fault.ToString(); exception.Message = e.Message; exception.Time = DateTime.UtcNow; exception.Exception = eInnerString; exception.StackTrace = e.StackTrace; exception.Method = e.TargetSite.Name; exception.Source = e.Source; db.ExceptionLogs.Add(exception); db.SaveChanges(); System.Diagnostics.Debug.WriteLine("Exception was logged to the database successfully."); } } catch { System.Diagnostics.Debug.WriteLine("Failed to log exception to database. We probably broke that too. :("); } }
/// <summary> /// /// </summary> /// <param name="ex"></param> public void AddExceptionLog(Exception ex) { Models.ExceptionLog objExceptionLog = new Models.ExceptionLog { Time = DateTime.Now, Message = ex.Message, Source = ex.Source, StackTrace = ex.StackTrace }; dataContext.ExceptionLog.InsertOnSubmit(objExceptionLog); dataContext.SubmitChanges(); }