Logging Server Errors to the Agility Web Logs

James Vidler -

The first step to troubleshooting any issue should be to check the Web Logs in AgilityCMS for your web server. If your Web Server isn't logging all your errors it can be almost impossible to pin point what's happening. 

Now, Agility.Web will automatically log things behind the scenes if there's an issue accessing content, page routing etc. However, for all your custom code that may be causing an exception you need to instruct your application to log those errors.

The Catch-all

The easiest way to just log whatever your last error is to setup some code in your Global.asax. The code below will grab the last exception that occurred in your generic Application_Error handler and instruct Agility.Web to log that error. 

protected void Application_Error(object sender, EventArgs e)
    Exception ex = Server.GetLastError();

    if (ex != null)

Manual Logging

There's always going to be cases where you've caught your error gracefully but still want to toss it into the Agility Web Logs so you can review it later. You can use the Agility.Web.Tracing.WebTrace class to log Info, Verbose, Warning, Error, and Exception.

            Agility.Web.Tracing.WebTrace.WriteException(ex, "Oops!");
Have more questions? Submit a request


Please sign in to leave a comment.