public void LogInfo(string message) { var entity = this.dbContext.ChangeTracker.Entries <TEntity>(); var type = entity.GetType(); try { using (var db = new instahangoutsEntities()) { var error = new LogData() { Application = "InstaHangouts", Message = message, Exception = message, Logged = DateTime.Now, LogLevel = "2", }; db.Entry(error); db.Set <LogData>().Add(error as LogData); db.SaveChanges(); } } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message1 = string.Format("{0}:{1}:{2}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage, validationError.PropertyName); // raise a new exception nesting // the current instance as InnerException raise = new InvalidOperationException(message1, raise); } } throw raise; } catch (Exception ex) { throw ex; } }
/// <summary> /// Logs the error. /// </summary> /// <param name="message">The message.</param> /// <param name="stackTrace">The stack trace.</param> /// <param name="innerException">The inner exception.</param> /// <param name="innerExceptionStackTrace">The inner exception stack trace.</param> public void LogError(Exception ex) { var entity = this.dbContext.ChangeTracker.Entries <TEntity>(); var type = entity.GetType(); using (var db = new instahangoutsEntities()) { var error = new LogData() { Application = "InstaHangouts", Message = ex.Message, Exception = ex.StackTrace, Logged = DateTime.Now, LogLevel = "2", Source = Convert.ToString(ex.InnerException) }; db.Entry(error); db.Set <LogData>().Add(error as LogData); db.SaveChanges(); } }