示例#1
0
        public static void LogException(Exception _exp, string _function, int _companyId)
        {
            tblExceptionLog Exlog = new tblExceptionLog();

            Exlog.CompanyId    = _companyId;
            Exlog.FunctionName = _function;
            Exlog.InnerMessage = "";
            Exlog.Message      = _exp.Message;
            Exlog.RecordDate   = DateTime.Now;
            Exlog.Source       = _exp.Source;

            DBEvents    db    = new DBEvents();
            DataContext cntxt = new DataContext(db.ConStr);

            try
            {
                if (cntxt.Connection.State == System.Data.ConnectionState.Closed)
                {
                    cntxt.Connection.Open();
                }

                cntxt.GetTable <tblExceptionLog>().InsertOnSubmit(Exlog);
                cntxt.SubmitChanges();
                cntxt.Connection.Close();
            }
            catch (Exception exp)
            {
                string str = exp.Message;
                cntxt.Connection.Close();
            }
        }
示例#2
0
        public static int WriteLogEntry(string exceptionType, string shortMessage, string fullMessage, string remark)
        {
            MainDataContextDataContext db = new MainDataContextDataContext();

            tblExceptionLog exception = new tblExceptionLog();

            exception.Id            = Guid.NewGuid();
            exception.ExceptionDate = DateTime.Now;

            exception.ExceptionType = exceptionType;
            exception.ShortMessage  = shortMessage;
            exception.FullMessage   = fullMessage;
            exception.Remark        = remark;
            try
            {
                exception.UserGuid = SecurityHelper.CurrentUserGuid;
                exception.UserName = SecurityHelper.CurrentUserName;
            }
            catch
            {
            }

            var id = db.spInsertException(
                Guid.NewGuid(),
                DateTime.Now,
                exceptionType,
                shortMessage,
                fullMessage,
                SecurityHelper.CurrentUserName,
                SecurityHelper.CurrentUserGuid,
                remark);

            int idNo = -999;

            int.TryParse(id.ReturnValue.ToString(), out idNo);

            db.Dispose();

            return(idNo);
        }