Logging Server Errors to the Agility Web Logs

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 pinpoint 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)
    {
       Agility.Web.Tracing.WebTrace.HandleApplicationError();
    }
}

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.WriteInfoLine("OK");
            Agility.Web.Tracing.WebTrace.WriteVerboseLine("Interesting...");
            Agility.Web.Tracing.WebTrace.WriteWarningLine("Weird...");
            Agility.Web.Tracing.WebTrace.WriteErrorLine("Bad!");
            Agility.Web.Tracing.WebTrace.WriteException(ex, "Oops!");

Trace Level Values

  • Verbose
    • Everything is outputted, including Verbose, Info, Warning, and Errors
  • Info
    • Info, Warning, and Errors are outputted.
  • Warning
    • Warnings and Errors are outputted.
    • *This is the normal default setting we recommend.
  • Error
    • Only Errors are outputted.

Setting Trace Level in Web.config

To set trace levels in web.config added the following trace level below:

<agility.web>
<settings applicationName="{Name}" developmentMode="true" contentCacheFilePath="c:\AgilityContent">
<websites>
<add websiteName="{WebsiteName}" securityKey="{SecurityKey}" />
</websites>
<trace traceLevel="Info" logFilePath="c:\AgilityLogs\SampleMVC4.log" emailErrors="false" />
</settings>
</agility.web>
0 out of 0 found this helpful

Comments

2 comments
  • can you add to this article the specific values for the traceLevel property in your agility.web node in web.config? 

     

    thanks,

     

    0
    Comment actions Permalink
  • Updated - thanks for the feedback, Mike!

    0
    Comment actions Permalink

Please sign in to leave a comment.