0

One shouldn't have to wrap every call to the database in a try/catch to accomplish this, should they? Can we just globally log all errors that occur, with one piece of code, vs. writing code to handle each and every possible area where one might occur? If so, how is this accomplished?


edit: I was hoping there was one place in ASP.NET MVC apps where I can place a bit of code to log information from exceptions.

M. Smith
  • 345
  • 3
  • 13
  • This post seems to talk about JSON errors, and also the use of Elmah, but I'd prefer not to use Elmah and I'd like to long any type of error (e.g. db, application). Basically, I need to know where I can add a bit of logging code (insert into an Error table) within an ASP.NET app. – M. Smith Aug 01 '16 at 15:11
  • 1
    No, not just that. The accepted answer shows you _a way_ how to do it. – kayess Aug 01 '16 at 15:12

1 Answers1

0

Use ExceptionFilter i.e. HandleError. You can add this filter on controllers. You can log errors through this filter.

Sarang
  • 83
  • 8