Beispiel #1
0
        public bool Add(string ModuleName, string FunctionName, System.Exception ex)
        {
            AUTH_EXCEPTIONAL_LOG ExLog = new AUTH_EXCEPTIONAL_LOG();

            ExLog.EXCEPTIONAL_LOG_ID = ExceptionalLogRepository.GetNewID("AUTH_EXCEPTIONAL_LOG", "EXCEPTIONAL_LOG_ID");
            ExLog.MODULE_NAME        = ModuleName;
            ExLog.FUNCTION_NAME      = FunctionName;
            ExLog.CATCH_TIME         = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            string ExcMsg = "";

            if (ex is System.Data.Entity.Validation.DbEntityValidationException)
            {
                ExcMsg = ((System.Data.Entity.Validation.DbEntityValidationException)ex).EntityValidationErrors.First().ValidationErrors.First().ErrorMessage;
            }
            else if (ex is System.Data.Entity.Validation.DbUnexpectedValidationException)
            {
            }
            else if (ex is System.Data.Entity.ModelConfiguration.ModelValidationException)
            {
            }
            else
            {
                ExcMsg = ex.Message;
            }


            ExLog.EXCEPTIONAL_TYPE        = ex.GetType().ToString();
            ExLog.EXCEPTIONAL_DESCRIPTION = ExcMsg;
            ExLog.STATE = "";
            ExceptionalLogRepository.Add(ExLog);
            ExceptionalLogRepository.SaveChanges();

            return(true);
        }
        public bool Delete(string exceptionalLogId, out string strResult)
        {
            strResult = string.Empty;
            bool result       = false;
            Guid exceptionid  = new Guid(exceptionalLogId);
            var  exceptionlog = ExceptionalLogRepository.GetQueryable().FirstOrDefault(lo => lo.ExceptionalLogID == exceptionid);

            if (exceptionlog != null)
            {
                try
                {
                    ExceptionalLogRepository.Delete(exceptionlog);
                    ExceptionalLogRepository.SaveChanges();
                    result = true;
                }
                catch (Exception e)
                {
                    strResult = "原因:" + e;
                }
            }
            else
            {
                strResult = "原因:未找到当前需要删除的数据!";
            }
            return(result);
        }
        public bool Emptys(out string strResult)
        {
            strResult = string.Empty;
            bool result       = false;
            var  exceptionlog = ExceptionalLogRepository.GetQueryable();

            if (exceptionlog != null)
            {
                foreach (var log in exceptionlog)
                {
                    ExceptionalLogRepository.Delete(log);
                }
                ExceptionalLogRepository.SaveChanges();
                result = true;
            }
            else
            {
                strResult = "原因:未找到当前需要删除的数据!";
            }
            return(result);
        }
        public bool CreateExceptionLog(string ModuleNam, string FunctionName, string ExceptionalType, string ExceptionalDescription, string State)
        {
            var moduleRepository = ModuleRepository.GetQueryable().Where(m => m.ModuleURL == ModuleNam).Select(m => new { modulname = m.ModuleName }).ToArray();

            if (moduleRepository.Length > 0)
            {
                var ExceptionalLogs = new ExceptionalLog()
                {
                    ExceptionalLogID       = Guid.NewGuid(),
                    CatchTime              = DateTime.Now.ToString(),
                    ModuleName             = moduleRepository[0].modulname,
                    FunctionName           = FunctionName,
                    ExceptionalType        = ExceptionalType,
                    ExceptionalDescription = ExceptionalDescription,
                    State = State,
                };
                ExceptionalLogRepository.Add(ExceptionalLogs);
                ExceptionalLogRepository.SaveChanges();
            }
            return(true);
        }