Exemple #1
0
        protected void WriteTrace(TraceRecord record)
        {
            if (record != null && record.Exception != null)
            {
                int    staffId  = 0;
                string usercode = string.Empty;

                var queryString = record.Request.RequestUri.Query;
                if (!String.IsNullOrWhiteSpace(queryString))
                {
                    int.TryParse(System.Web.HttpUtility.ParseQueryString(queryString.Substring(1))["staffId"], out staffId);
                    usercode = CommonDBFunctions.GetCurrentUser(staffId);
                }
                else
                {
                    usercode = "MobileApi";
                }

                var errorMessage = string.Format(
                    "{0} {1}: Category={2}, Level={3} {4} {5} {6} {7}",
                    record.Request.Method.ToString(),
                    record.Request.RequestUri.ToString(),
                    record.Category,
                    record.Level,
                    record.Kind,
                    record.Operator,
                    record.Operation,
                    record.Exception != null ? record.Exception.GetBaseException().Message : !string.IsNullOrEmpty(record.Message) ? record.Message : string.Empty);

                _ctx.ssp_SCLogError(errorMessage, record.Exception.StackTrace, "MobileErrorTrace", usercode, DateTime.Now, "");
            }
        }
Exemple #2
0
        public void LogError(ErrorLogModel errorlog, int StaffId = 0)
        {
            try
            {
                string usercode = string.Empty;
                if (errorlog != null)
                {
                    if (StaffId > 0)
                    {
                        usercode = _ctx.Staffs
                                   .Where(s => s.StaffId == StaffId)
                                   .Select(s => s.UserCode).FirstOrDefault();
                    }
                    else
                    {
                        usercode = "CommonUser";
                    }

                    _ctx.ssp_SCLogError(errorlog.ErrorMessage, errorlog.VerboseInfo, errorlog.ErrorType, usercode, DateTime.Now, errorlog.DataSetInfo);
                }
            }
            catch (Exception ex)
            {
                Exception excep = new Exception("Exception occured in ErrorLogRepository.LogError method." + ex.Message);
                throw excep;
            }
        }