Logging Errors with Umbraco

Umbraco, .NET, C#

It is simple to log errors with Umbraco. I make a habit of logging any caught exceptions in my code to the Umbraco log by using the LogHelper class.

try
{
    // code that throws exception
}
catch (Exception ex)
{
    LogHelper.Error(this.GetType(), "Your custom error message here", ex);
}
 

The custom error message is logged along with details of the exception to /App_Data/Logs/UmbracoTraceLog.txt. This makes diagnosing site issues where you are unable to step into the code, or finding out the reason for historical errors, a lot easier.

Comments