Beispiel #1
0
        //extension method for exception logging at the server
        public static bool Log(this Exception ex)
        {
            try
            {
                ErrorClass err = new ErrorClass();
                err.Message    = ex.Message;
                err.StackTrace = ex.StackTrace;
                dynamic status = new ErrorController().PostError(err, "InterenalErrorLog.txt");

                return(status.Status);
            }
            catch
            {
                return(false);
            }
        }
Beispiel #2
0
        public object PostError([FromBody] ErrorClass errorObj, string logFile = "ConsumerErrorLog.txt")
        {
            try
            {
                bool   status;
                string path = Values.RootAddress + "App_Data\\" + logFile;

                string lastNumber = LastExceptionNumber(path);

                if (lastNumber != "Error")
                {
                    string newNumber = (int.Parse(lastNumber) + 1) + "";
                    using (StreamWriter sw = File.AppendText(path))
                    {
                        string errorMessage = "\r\n\r\nDate: " + DateTime.Now.ToLongDateString() + "\r\nTime: " + DateTime.Now.ToLongTimeString() +
                                              "\r\nError message: " + errorObj.Message +
                                              "\r\nError's stack trace: " + errorObj.StackTrace +
                                              "\r\n#########################################################################################\r\n\r\n\r\n" +
                                              "Exception " + newNumber;
                        sw.Write(errorMessage);
                        sw.Flush();
                    }
                    status = true;
                }
                else
                {
                    status = false;
                }

                var response = new { Status = status };                     //send the encoded response as an anonymous object

                return(response);
            }

            catch
            {
                throw new ExternalException();
            }
        }