Exemple #1
0
        /// <summary>
        /// Format an exception and message, and then log it
        /// </summary>
        /// <param name="ex">Exception</param>
        /// <param name="message">Additional message regarding the exception</param>
        /// <param name="notifyAdmin">If true, an email will be sent to admin</param>
        public static void LogError(Exception ex, string message, bool notifyAdmin, string subject = "Credential Finder Exception encountered")
        {
            //string userId = "";
            string sessionId    = "unknown";
            string remoteIP     = "unknown";
            string path         = "unknown";
            string queryString  = "unknown";
            string url          = "unknown";
            string parmsString  = "";
            string lRefererPage = "";

            try
            {
                if (UtilityManager.GetAppKeyValue("notifyOnException", "no").ToLower() == "yes")
                {
                    notifyAdmin = true;
                }
                if (HttpContext.Current != null)
                {
                    sessionId = HttpContext.Current.Session.SessionID.ToString();
                    remoteIP  = HttpContext.Current.Request.ServerVariables["REMOTE_HOST"];

                    if (HttpContext.Current.Request.UrlReferrer != null)
                    {
                        lRefererPage = HttpContext.Current.Request.UrlReferrer.ToString();
                    }
                    string serverName = UtilityManager.GetAppKeyValue("serverName", HttpContext.Current.Request.ServerVariables["LOCAL_ADDR"]);
                    path = serverName + HttpContext.Current.Request.Path;

                    if (IsValidRequestString() == true)
                    {
                        queryString = HttpContext.Current.Request.Url.AbsoluteUri.ToString();
                        //url = GetPublicUrl( queryString );

                        url = HttpContext.Current.Server.UrlDecode(queryString);
                        //if ( url.IndexOf( "?" ) > -1 )
                        //{
                        //    parmsString = url.Substring( url.IndexOf( "?" ) + 1 );
                        //    url = url.Substring( 0, url.IndexOf( "?" ) );
                        //}
                    }
                    else
                    {
                        url = "suspicious url encountered!!";
                    }
                }
                //????
                //userId = WUM.GetCurrentUserid();
            }
            catch
            {
                //eat any additional exception
            }

            try
            {
                string errMsg = message +
                                "\r\nType: " + ex.GetType().ToString() + ";" +
                                "\r\nSession Id - " + sessionId + "____IP - " + remoteIP +
                                "\r\rReferrer: " + lRefererPage + ";" +
                                "\r\nException: " + ex.Message.ToString() + ";" +
                                "\r\nStack Trace: " + ex.StackTrace.ToString() +
                                "\r\nServer\\Template: " + path +
                                "\r\nUrl: " + url;

                if (ex.InnerException != null && ex.InnerException.Message != null)
                {
                    errMsg += "\r\n****Inner exception: " + ex.InnerException.Message;

                    if (ex.InnerException.InnerException != null && ex.InnerException.InnerException.Message != null)
                    {
                        errMsg += "\r\n@@@@@@Inner-Inner exception: " + ex.InnerException.InnerException.Message;
                    }
                }

                if (parmsString.Length > 0)
                {
                    errMsg += "\r\nParameters: " + parmsString;
                }

                LoggingHelper.LogError(errMsg, notifyAdmin, subject);
            }
            catch
            {
                //eat any additional exception
            }
        }         //