0

when exception is thrown in my controller, action's are getting executed again and again, when error is thrown this cycle is going on.

 try
  {
                    LogManager.Info("Call:" + invocation.TargetType.Name + "::" + invocation.Method.Name);
                    var startTime = DateTime.Now;
                    invocation.Proceed();
                    var endTime = DateTime.Now;
                    LogManager.Info("CallEnd:" + invocation.TargetType.Name + "::" + invocation.Method.Name + " Execution Time(Milliseconds): " + (endTime - startTime).Milliseconds);
                }
                catch (Exception ex)
                {                
                    //HttpContext.Current.Request.Abort();
                    var builder = new StringBuilder();
                    var dataSource = ConfigurationManager.ConnectionStrings["dbMain"].ToString().Split(';')[0];

                    builder.AppendLine();
                    builder.AppendLine(string.Concat(Enumerable.Repeat(">", 50)));
                    builder.AppendLine("Server Time:-" + DateTime.Now);
                    //builder.AppendLine("Requested Url:" + HttpContext.Current.Request.Url);
                    builder.AppendLine(dataSource);
                    builder.AppendLine("Error at " + invocation.TargetType.Name + "::" + invocation.Method.Name + "(" + JsonConvert.SerializeObject(invocation.Arguments, Formatting.Indented) + ")");
                    builder.AppendLine(string.Concat(Enumerable.Repeat("-", 50)));
                    builder.AppendLine(JsonConvert.SerializeObject(ex, Formatting.Indented).Replace("\\n", System.Environment.NewLine));
                    builder.AppendLine(string.Concat(Enumerable.Repeat("<", 50)));

                    LogManager.Error(builder.ToString());
                    LogManager.SendMail(ex, builder.ToString());

                    throw;
                } 
Nikki
  • 409
  • 1
  • 5
  • 15
  • 2
    " i want to stop exception from bubbling up and re-executing the request multiple times" X 4 -- are you trying to be meta or something? – rory.ap Mar 22 '17 at 11:41

1 Answers1

0

If you want the exception to stop bubbling up, don't re-throw it. In your code there is the : "throw ;" line. Remove it.

Shrulik
  • 284
  • 2
  • 11