title: Asp.net MVC 3 500 Error logging not working on server
body: <p>I have configured an error 500 page with a controller an a view to display when a 500 occures via the webconfig.</p>
  
  <pre><code>   &lt;httpErrors errorMode="Custom" existingResponse="Replace"&gt;
          &lt;remove statusCode="404" /&gt;
          &lt;remove statusCode="500" /&gt;
          &lt;error statusCode="404" responseMode="ExecuteURL" path="/error/404" /&gt;
          &lt;error statusCode="500" responseMode="ExecuteURL" path="/error/500" /&gt;
      &lt;/httpErrors&gt;
  </code></pre>
  
  <p>In the application_error event i log the error</p>
  
  <pre><code>    protected void Application_Error(object sender, EventArgs e)
      {
          var objErr = Server.GetLastError().GetBaseException();
          var err = string.Concat("Error in: ", Request.Url, "\nMessage:", objErr.Message, "\nStack Trace:", objErr.StackTrace);
          DatabaseLogging.WriteLog(err, 3);
      }
  </code></pre>
  
  <p>On my dev envirement it works perfect, the exception is logged and the error page is shown. On the acceptance envirment the 500 error page is show, but the real error is not logged. The following error gets logged.</p>
  
  <pre><code>Message:The view 'Error' or its master was not found or no view engine supports the searched locations. The following locations were searched:  ~/Views/User/Error.aspx  ~/Views/User/Error.ascx  ~/Views/Shared/Error.aspx  ~/Views/Shared/Error.ascx  ~/Views/User/Error.cshtml  ~/Views/User/Error.vbhtml  ~/Views/Shared/Error.cshtml  ~/Views/Shared/Error.vbhtml Stack Trace:   at System.Web.Mvc.ViewResult.FindView(ControllerContext context)     at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)     at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)     at System.Web.Mvc.Controller.ExecuteCore()     at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)     at System.Web.Mvc.MvcHandler.&lt;&gt;c__DisplayClass6.&lt;&gt;c__DisplayClassb.&lt;BeginProcessRequest&gt;b__5()     at System.Web.Mvc.Async.AsyncResultWrapper.&lt;&gt;c__DisplayClass1.&lt;MakeVoidDelegate&gt;b__0()     at System.Web.Mvc.MvcHandler.&lt;&gt;c__DisplayClasse.&lt;EndProcessRequest&gt;b__d()     at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()     at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously)
  </code></pre>
  
  <p>Anyone got an idea how I can solve this problem?
  the following routes are mapped:</p>
  
  <pre><code>        // Error pages
          routes.MapRoute("Error404", "error/404", new { controller = "Error", action = "Error404" });
          routes.MapRoute("Error500", "error/500", new { controller = "Error", action = "Error500" });
  </code></pre>