Esempio n. 1
0
        public ErrorExceptionLogs Add(ErrorExceptionLogs ErrorExceptionLogs)
        {
            using (IDbConnection _db = OpenConnection())
            {
                try
                {
                    var parameters = new DynamicParameters();
                    parameters.Add("Source", ErrorExceptionLogs.Source);
                    parameters.Add("LogDateTime", DateTime.Now.ToString("g"));
                    parameters.Add("Message", ErrorExceptionLogs.Message);
                    parameters.Add("QueryString", ErrorExceptionLogs.QueryString);
                    parameters.Add("TargetSite", ErrorExceptionLogs.TargetSite);
                    parameters.Add("StackTrace", ErrorExceptionLogs.StackTrace);
                    parameters.Add("ServerName", ErrorExceptionLogs.ServerName);
                    parameters.Add("RequestURL", ErrorExceptionLogs.RequestURL);
                    parameters.Add("UserAgent", ErrorExceptionLogs.UserAgent);
                    parameters.Add("UserIP", ErrorExceptionLogs.UserIP);
                    parameters.Add("UserAuthentication", ErrorExceptionLogs.UserAuthentication);
                    parameters.Add("UserName", ErrorExceptionLogs.UserName);
                    parameters.Add("EventId", dbType: DbType.Int32, direction: ParameterDirection.Output);

                    var EventId = _db.Query <int>("SaveErrorExceptionLogs", parameters, commandType: CommandType.StoredProcedure).SingleOrDefault();
                    ErrorExceptionLogs.EventId = EventId;
                    return(ErrorExceptionLogs);
                }
                catch (Exception ex)
                {
                    string ErrorMsg = ex.Message.ToString();
                    errLog.LogError(ex);
                    return(null);
                }
            }
        }
Esempio n. 2
0
        public void Delete(ErrorExceptionLogs model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("ErrorExceptionLogs");
            }

            List <ErrorExceptionLogs> ErrorExceptionLogs = GetAll();

            ErrorExceptionLogs.Remove(ErrorExceptionLogs.Find(l => l.EventId == model.EventId));
            UnitOfWork.ErrorExceptionLogsRepository.Delete(model);
        }
Esempio n. 3
0
        public void Insert(ErrorExceptionLogs model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("ErrorExceptionLog");
            }

            List <ErrorExceptionLogs> ErrorExceptionLogs = GetAll();

            ErrorExceptionLogs.Add(model);
            UnitOfWork.ErrorExceptionLogsRepository.Insert(model);
        }
Esempio n. 4
0
        public void LogError(Exception ex)
        {
            string strMessage = string.Empty, strSource = string.Empty, strTargetSite = string.Empty, strStackTrace = string.Empty;

            while (ex != null)
            {
                strMessage    = ex.Message;
                strSource     = ex.Source;
                strTargetSite = ex.TargetSite.ToString();
                strStackTrace = ex.StackTrace;
                ex            = ex.InnerException;
            }

            if (strMessage.Length > 0)
            {
                try
                {
                    ErrorExceptionLogs errorExceptionLog = new ErrorExceptionLogs();
                    errorExceptionLog.RequestURL = GetExecutingMethodName(ex);

                    var parameters = new DynamicParameters();
                    parameters.Add("Source", strSource);
                    parameters.Add("LogDateTime", DateTime.Now.ToString("g"));
                    parameters.Add("Message", strMessage);
                    parameters.Add("QueryString", errorExceptionLog.QueryString);
                    parameters.Add("TargetSite", strTargetSite);
                    parameters.Add("StackTrace", strStackTrace);
                    parameters.Add("ServerName", errorExceptionLog.ServerName);
                    parameters.Add("RequestURL", errorExceptionLog.RequestURL);
                    parameters.Add("UserAgent", errorExceptionLog.UserAgent);
                    parameters.Add("UserIP", errorExceptionLog.UserIP);
                    parameters.Add("UserAuthentication", errorExceptionLog.UserAuthentication);
                    parameters.Add("UserName", errorExceptionLog.UserName);
                    parameters.Add("EventId", dbType: DbType.Int32, direction: ParameterDirection.Output);

                    using (IDbConnection _db = OpenConnection())
                    {
                        string query = "SaveErrorExceptionLogs";
                        _db.Execute(query, parameters, commandType: CommandType.StoredProcedure);
                    }
                }
                catch (Exception exc)
                {
                    //StringBuilder sb = new StringBuilder();
                    //sb.Append("Database Error From Exception Log!");
                    //sb.Append("Source : " + exc.Source);
                    //sb.Append("Message : " + exc.Message);
                    //WriteLog(sb.ToString());
                    EventLog.WriteEntry(exc.Source, "Database Error From Exception Log!", EventLogEntryType.Error, 65535);
                }
            }
        }
Esempio n. 5
0
        public void Update(ErrorExceptionLogs model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("ErrorExceptionLog");
            }

            ErrorExceptionLogs ErrorExceptionLog = GetById(model.EventId.ToString());

            if (ErrorExceptionLog != null)
            {
                UnitOfWork.ErrorExceptionLogsRepository.Update(model);
            }
        }