Exemple #1
0
        /// <summary>
        /// specified error message and a reference to the inner exception that is
        /// the cause of this exception.
        /// </summary>
        ///<param name="objException">The exception that is the cause of the current
        /// exception.  If the innerException parameter is not a <see langword="null"/> reference,
        /// the current exception is raised in a catch block that handles the inner
        /// exception.
        /// </param>
        /// <param name="folderCreationMode">Specifies the folder creation type</param>
        /// <param name="mode">Specifies Product Mode</param>
        /// <param name="errorMode">Specifies Error Mode</param>
        /// <param name="searchId">SearchId for identifier.</param>
        /// <param name="portal">Specifies Portal</param>
        /// <param name="module">Specifies module</param>
        /// <returns> true if log was written successfully; false otherwise</returns>
        public static bool WriteErrorLog(Exception objException, FolderCreationMode folderCreationMode, ProductMode mode, ErrorMode errorMode, string searchId, string portal, string module)
        {
            bool   bReturn      = false;
            string strException = string.Empty;

            try
            {//Inactive conversation
                if (objException.Message.ToUpper().Contains("INACTIVE CONVERSATION"))
                {
                    ClearSessionPool();
                }
                if (string.IsNullOrEmpty(searchId))
                {
                    searchId = DateTime.Now.ToString(CultureInfo.InvariantCulture).Replace("/", "").Replace(" ", "").Replace(":", "").Replace("AM", "").Replace("PM", "");
                }
                var sw = new StringBuilder();
                sw.Append("Source		: "+ objException.Source.ToString().Trim());
                sw.Append("Method		: "+ objException.TargetSite.Name.ToString());
                sw.Append("Date		: "+ DateTime.Now.ToLongTimeString());
                sw.Append("Time		: "+ DateTime.Now.ToShortDateString());
                sw.Append("Error		: "+ objException.Message.ToString().Trim());
                sw.Append("Stack Trace	: "+ objException.StackTrace.ToString().Trim());
                string path = GetErrorLogFilePath(folderCreationMode, searchId);
                WriteException(path, sw.ToString());
                //LogException.clsLogException objLog = new LogException.clsLogException();
                //objLog.WriteException(Mode.ToString(), "Flights", objException.Message);//Module, Product, Error Msg

                //sw = new StreamWriter(GetErrorLogFilePath(folderCreationMode), true);
                //sw.WriteLine("Source		: " + objException.Source.ToString().Trim());
                //sw.WriteLine("Method		: " + objException.TargetSite.Name.ToString());
                //sw.WriteLine("Date		: " + DateTime.Now.ToLongTimeString());
                //sw.WriteLine("Time		: " + DateTime.Now.ToShortDateString());
                //sw.WriteLine("Computer	: " + Dns.GetHostName().ToString());
                //sw.WriteLine("Error		: " + objException.Message.ToString().Trim());
                //sw.WriteLine("Stack Trace	: " + objException.StackTrace.ToString().Trim());
                //sw.WriteLine("^^-------------------------------------------------------------------^^");
                //sw.Flush();
                //sw.Close();

                using (var objLoggerData = new LoggerData())
                {
                    var intMsg = objLoggerData.SaveLogError(searchId, errorMode.ToString(), objException.StackTrace.ToString(), portal, !string.IsNullOrEmpty(module) ? module : mode.ToString());
                }

                #region Send Log / Error Email to admininistrators
                PreEmail.SendLogMail(objException.StackTrace.ToString(), searchId);
                #endregion

                #region Send Log / Error SMS to admininistrators
                if (errorMode.ToString().ToLower() == "critical")
                {
                    using (SendSMS objSendSMS = new SendSMS())
                    {
                        objSendSMS.MobileNo = ConfigurationSettings.AppSettings["ErrorPhoneNoTo"].ToString();
                        objSendSMS.Message  = "New exception occurred on BMT(SearchId : " + searchId + ")";
                        objSendSMS.CallSMS();
                    }
                }
                #endregion


                bReturn = true;
            }
            catch (Exception ex)
            {
                bReturn = false;
            }
            return(bReturn);
        }