public bool saveErrorInDB(ErrorRestViewModel err)
        {
            bool result = false;

            Error error1 = new Error()
            {
                errorDescription = err.errorDescription,
                logLevel         = err.logLevel,
                applicationID    = err.appID,
                exceptionMessage = err.exceptionMessage,
                timestamp        = err.timestamp.ToString()
            };

            using (ErrorLoggerDBContext context = new ErrorLoggerDBContext())
            {
                try
                {   //check if app ID exist - If App ID does not exist context.savechanges will fail and this will be catched in catch block.
                    context.Errors.Add(error1);
                    context.SaveChanges();
                    result = true;
                }
                catch (Exception ex)
                {
                    Log.Error("LoadersnLogic//SaveErrorinDB " + ex.Message);
                    throw ex;
                }
            }

            return(result);
        }
Beispiel #2
0
        // POST api/values
        public void Post(ErrorRestViewModel error)
        {
            Log.Debug("POST Request traced");
            ErrorLoggerHandler errorLoggerhandler_ = new ErrorLoggerHandler();

            //call the database to add into database
            try
            {
                errorLoggerhandler_.saveErrorInDB(error);
            }catch (Exception ex)
            {
                Log.Debug("Database Save Error: " + ex.Message);
                HttpResponseMessage message = new HttpResponseMessage(HttpStatusCode.InternalServerError);
                message.Content      = new StringContent(ex.Message);
                message.ReasonPhrase = "Not able to save the error in DB. Check if application ID is correct.";
                throw new HttpResponseException(message);
            }
        }