Beispiel #1
0
        public CustomError customErrorLogger(string stringMsg, Exception ex, ILog errorLogger)
        {
            try
            {
                CustomError objCustomError = new CustomError();
                Guid        msgId          = Guid.NewGuid();
                string      logErrorMsg    = string.Empty;
                // logErrorMsg = stringMsg + Environment.NewLine + "Error Reason :" + ex.Message.ToString();
                logErrorMsg               = stringMsg;// +Environment.NewLine + "Error Reason :" + ex.Message.ToString();
                objCustomError.msgId      = msgId;
                objCustomError.errMessage = logErrorMsg;

                StringBuilder sb = new StringBuilder();
                CreateExceptionString(sb, ex, string.Empty);
                objCustomError.stackTraceDescription = sb.ToString();

                //Logging
                log4net.GlobalContext.Properties["fname"] = msgId.ToString();
                log4net.Config.XmlConfigurator.Configure();
                errorLogger.Error(logErrorMsg);
                errorLogger.Error(objCustomError.stackTraceDescription);
                //return objList;
                return(objCustomError);
            }
            catch (Exception e)
            {
                throw;
            }
            finally
            {
                errorLogger = null;
            }
        }
Beispiel #2
0
        public void throwJsonResponse(CustomError response)
        {
            string jsonMsg = Utility.SerializeJson(response, true);
            OutgoingWebResponseContext context = WebOperationContext.Current.OutgoingResponse;

            context.StatusCode        = HttpStatusCode.InternalServerError;
            context.StatusDescription = jsonMsg;
            HttpContext.Current.Response.Write(context.StatusDescription.ToString());
        }
Beispiel #3
0
        public CustomError getErrorResponse(string response)
        {
            CustomError objCustomError = new CustomError();
            string      errMessage     = string.Empty;
            string      stackTrace     = string.Empty;
            XDocument   xd             = XDocument.Parse(response);

            IEnumerable <XElement> childElements = from el in xd.Root.Elements()
                                                   select el;

            foreach (var s in childElements)
            {
                if (s.Name.LocalName.Equals("messages"))
                {
                    objCustomError.errMessage = s.Value;
                }
                if (s.Name.LocalName.Equals("status_text"))
                {
                    objCustomError.stackTraceDescription = s.Value;
                }
            }

            return(objCustomError);
        }