Logging ASP.NET Application Errors for later inspection
This guide is obsolete, we recommend using Elmah or just the built-in error logging
AppHarbor logs every unhandled exception and expose it in the interface. If you want more control over the data that should be logged, you can log application errors yourself. We have created an example project demonstrating how. The gist of it is in Global.asax.cs:
protected void Application_Error(object sender, EventArgs e)
{
try
{
var exception = Server.GetLastError();
var logEntry = new LogEntry
{
Date = DateTime.Now,
Message = exception.Message,
StackTrace = exception.StackTrace,
};
var datacontext = new LogDBDataContext();
datacontext.LogEntries.InsertOnSubmit(logEntry);
datacontext.SubmitChanges();
}
catch (Exception)
{
// failed to record exception
}
}