/// <summary> Save data to the ErrorLog table in the DB </summary> /// <param name="dto"> The object containing the value </param> public bool Log(LoggingDTO dto) { if (ValidateData(dto)) { try { ErrorLog model = new ErrorLogMapper().MapDtoToModel(dto); _context.ErrorLog.Add(model); return(true); } catch (Exception) { return(false); } } else { try { _context.ErrorLog.Add(new ErrorLog { AppLocation = "ErrorLogRepository - Log()", DateOccurred = DateTime.Now, DeveloperComment = "An error could not be logged because at least one required field was missing." }); } catch (Exception) { } } return(false); }
public ErrorLog MapDtoToModel(LoggingDTO dto) { return(new ErrorLog { AppLocation = dto.AppLocation, DateOccurred = DateTime.Now, DeveloperComment = dto.DeveloperComment, ExceptionMessage = dto.ExceptionMessage ?? null, ExceptionStacktrace = dto.ExceptionStacktrace ?? null, }); }
private bool ValidateData(LoggingDTO l) { if (string.IsNullOrEmpty(l.AppLocation)) { return(false); } if (string.IsNullOrEmpty(l.DeveloperComment)) { return(false); } return(true); }
/// <summary> Log an error/exception which occurred within the system </summary> /// <param name="comment"> Any additional description or developer comment to describe the error. </param> /// <param name="occurredWithin"> Should describe specifically where the error occurred. </param> /// <param name="exception"> Optional: a exception which was caught during a specific execution of a procedure. </param> public void LogApplicationError(string comment, string occurredWithin, Exception exception = null) { LoggingDTO dto = new LoggingDTO { DeveloperComment = comment, AppLocation = occurredWithin, ExceptionMessage = exception?.Message, ExceptionStacktrace = exception?.StackTrace }; var r = _unitOfWork.ErrorLogs.Log(dto); if (r) { _unitOfWork.Complete(); } }