Jacob Rohde
Jacob Rohde

Reputation: 921

Error logging in ASP.NET MVC 3

I am logging errors in my ASP.NET MVC 3's Application_Error method in the Global.asax file. My problem is that if customErrors in Web.config is set to true no logging happens. It does happen if it is set to Off. If an exception is thrown, Application_Error will always be called no matter the customError settings - or so I thought? What is up?

Upvotes: 1

Views: 2802

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038710

The possible values of the mode attribute are On, Off and RemoteOnly so I suspect that if you set it to true your application wouldn't even load.

On the other hand if you set mode="On" in case of an exception there is a global error filter in ASP.NET MVC 3 (see the RegisterGlobalFilters method in your Global.asax) which kicks in and automatically renders the ~/Views/Shared/Error.cshtml view => in this case the Application_Error method won't be called because the exception is handled.

Upvotes: 5

Related Questions