Exemplo n.º 1
0
        private void BuildStats()
        {
            // get stats in past 0 days, i.e., Today

            ErrorLogDa da         = new ErrorLogDa();
            int        errorCount = da.GetRecentErrorCount(0);

            ErrorCount.Text = errorCount.ToString();

            UserDa uDa        = new UserDa();
            int    loginCount = uDa.GetUserLoginCount(0);

            UserLoginCount.Text = loginCount.ToString();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Logs the exception to the Caisis database.
        /// </summary>
        /// <param name="ex">The exception to be published.</param>
        public static void WriteToDatabaseLog(Exception ex)
        {
            string ErrUserName = "";

            HttpRequest      req = HttpContext.Current.Request;
            HttpSessionState ses = HttpContext.Current.Session;

            string ErrURL      = req.Url.ToString();
            string ErrFullPath = req.PhysicalPath.ToString();//.Replace("\\",".");

            string ErrFileName = ErrFullPath.Substring(ErrFullPath.LastIndexOf("\\") + 1);

            string ErrQueryString = req.QueryString.ToString();
            string ErrForm        = req.Form.ToString();

            //Remove viewstate and such
            if (ErrForm.Length > 0)
            {
                string[] aErrForm = ErrForm.Split('&');
                ErrForm = "";
                for (int i = 0; i < aErrForm.Length; i++)
                {
                    if (!aErrForm[i].StartsWith("__"))
                    {
                        ErrForm = ErrForm + aErrForm[i] + "&";
                    }
                }
            }

            string ErrBrowser       = req.Browser.Type.ToString() + " (" + req.Browser.Version.ToString() + ")";
            string ErrPlatform      = req.Browser.Platform.ToString();
            string ErrCookies       = req.Browser.Cookies.ToString();
            string ErrJavascript    = req.Browser.JavaScript.ToString() + " (" + req.Browser.EcmaScriptVersion + ")";
            string ErrIP            = req.UserHostAddress.ToString();
            string ErrAuthenticated = req.IsAuthenticated.ToString();
            string ErrHostName      = req.UserHostName;

            // user Roles
            string ErrPermList = "";

            //session info
            string ErrSessionIsNew   = "";
            int    ErrLoginId        = -1;
            int    ErrSessionTimeOut = -1;
            int    ErrPatientId      = -1;
            int    ErrDatasetId      = -1;

            //TODO: Add tab info

            //path after core
            //to show the section

            DateTime?ErrTicketIssueDate  = null;
            DateTime?ErrTicketExpiration = null;

            DateTime ErrorTime = DateTime.Now;

            string ErrMachineName = HttpContext.Current.Server.MachineName;

            string ErrorName     = "";
            string ErrorMessage  = "";
            string ErrStackTrace = "";

            if (HttpContext.Current.User != null)
            {
                ErrUserName = HttpContext.Current.User.Identity.Name;
            }


            if (req.Cookies["dsPerms"] != null)
            {
                ErrPermList = CustomCryptoHelper.EasyDecrypt(req.Cookies["dsPerms"].Value.ToString());
            }
            else
            {
                ErrPermList = "User permissions cookie does not exist.";
            }

            if (ses != null)
            {
                ErrSessionIsNew = ses.IsNewSession.ToString();

                if (ses[SessionKey.LoginId] != null)
                {
                    if (PageUtil.IsInteger(ses[SessionKey.LoginId].ToString()))
                    {
                        ErrLoginId = int.Parse(ses[SessionKey.LoginId].ToString());
                    }

                    ErrSessionTimeOut = ses.Timeout;

                    if (ses[SessionKey.PatientId] != null)
                    {
                        if (PageUtil.IsInteger(ses[SessionKey.PatientId].ToString()))
                        {
                            ErrPatientId = int.Parse(ses[SessionKey.PatientId].ToString());
                        }
                    }

                    if (ses[SessionKey.DatasetId] != null)
                    {
                        if (PageUtil.IsInteger(ses[SessionKey.DatasetId].ToString()))
                        {
                            ErrDatasetId = int.Parse(ses[SessionKey.DatasetId].ToString());
                        }
                    }
                }
                else
                {
                    //"User does not have a Session.LoginId."
                }
            }
            else
            {
                //"HttpContext.Current.Session is null. No session information available."
            }


            //cookie info
            if (HttpContext.Current.User != null && HttpContext.Current.User.Identity is FormsIdentity)
            {
                FormsAuthenticationTicket ticket = ((FormsIdentity)HttpContext.Current.User.Identity).Ticket;

                ErrTicketIssueDate  = ticket.IssueDate;
                ErrTicketExpiration = ticket.Expiration;
            }

            if (ex != null)
            {
                ErrorName    = ex.GetType().Name;
                ErrorMessage = ex.Message;
                // ErrStackTrace = ex.StackTrace;
                ErrStackTrace = ex.ToString();
            }

            // log error details to db
            ErrorLogDa elda = new ErrorLogDa();

            elda.LogError(ErrLoginId,
                          ErrDatasetId,
                          ErrPatientId,
                          ErrUserName,
                          ErrURL,
                          ErrFullPath,
                          ErrFileName,
                          ErrForm,
                          ErrQueryString,
                          ErrBrowser,
                          ErrPlatform,
                          ErrJavascript,
                          ErrIP,
                          ErrAuthenticated,
                          ErrHostName,
                          ErrPermList,
                          ErrSessionIsNew,
                          ErrSessionTimeOut,
                          ErrTicketIssueDate,
                          ErrTicketExpiration,
                          ErrorTime,
                          ErrMachineName,
                          ErrorName,
                          ErrorMessage,
                          ErrStackTrace
                          );
        }