LeanSentry tracks every error across the server, IIS, and ASP.NET application stack. However, in some configurations ASP.NET may not provide complete error information for request errors, which will cause LeanSentry to under-report ASP.NET errors, and in some cases to never show them.
To enable accurate ASP.NET error tracking, you will need to make 2 small changes to your application:
1. Enable every ASP.NET error to be logged (in all ASP.NET applications)
2. If your error handling handles application exceptions, log them to LeanSentry with Leansentry.ApplicationMonitoring.dll.
3. For ASP.NET MVC applications, deploy LeanSentry.ApplicationMonitoring.Mvc.dll (or update default HandleErrorAttribute to fix error logging).
Make sure ASP.NET exception logging is on (all ASP.NET applications)
Open your environment settings, and check "Enable full ASP.NET error tracking":
This will cause LeanSentry to enable full ASP.NET error logging to the Event Log for all ASP.NET applications on the server, by making a small change to the default ASP.NET Health Monitoring configuration in the Framework's root web.config (for 32 bit and 64 bit frameworks of all currently-installed versions).
NOTE: Consider making this change during off-peak times, because it can cause your ASP.NET applications to restart the first time it's applied.
Alternatively, you can make the following change directly to your application's web.config:
-
<system.web> <!-- Add this section --> <healthMonitoring> <rules> <!-- Make sure all errors are logged to the EventLogProvider ("Default" profile only allows 1 error per minute) --> <remove name="All Errors Default" /> <add name="All Errors Default" eventName="All Errors" profile="Critical" provider="EventLogProvider" /> </rules> </healthMonitoring> </system.web>
If your application handles errors, log them to LeanSentry using Leansentry.ApplicationMonitoring.dll
Many applications have their own error handling, by catching exceptions at the page, or application level. Some examples of this are:
- Try/catch in application code
- Handling exceptions in the ASPX Page.Error event
- Handling exceptions in the Application.Error event in global.asax
If your application handles the exceptions, or calls Server.ClearError(), those exceptions will not be reported via the standard ASP.NET unhandled error reporting mechanism and therefore LeanSentry will not see them.
You can easily route those exceptions to LeanSentry WITHOUT changing the behavior of your error handers, by doing the following:
1. Deploy the LeanSentry.ApplicationMonitoring.dll library to your application.
2. Log the exception to LeanSentry inside your error handler with a single line of code:
HttpContextBase context = ...;
Exception error = ...;
LeanSentry.ApplicationMonitoring.Monitoring.LogError(context, error);
NOTE: We recommend you do this in a single place where all your errors are being captured. If you have multiple pages/places that log errors, place this code inside a central error handler method you create for your entire application.
NOTE: This is NOT necessary in cases where you allow the exception to bubble out/be reported by ASP.NET as normal.
For ASP.NET MVC applications
OPTION 1: Use LeanSentry.ApplicationMonitoring.Mvc.dll to automatically route exceptions to Leansentry
ASP.NET MVC's default HandleError attribute will not report the exceptions correctly by default. To correct this behavior and make sure MVC exceptions are visible in LeanSentry's comprehensive error tracking:
1. Deploy the LeanSentry.ApplicationMonitoring.dll library to your application.
This will automatically make sure the MVC exceptions are tracked automatically whenever you use the HandleErrorAttribute. If you would rather make these changes manually without using ApplicationMonitoring.dll, see the next section.
OPTION 2: (Without LeanSentry.ApplicationMonitoring.Mvc.dll) Update default HandleErrorAttribute to fix error logging
1. Make the following change in your global.asax.cs:
public class MvcApplication : System.Web.HttpApplication { public static void RegisterGlobalFilters(GlobalFilterCollection filters) { // Use the fixed HandleErrorAttributeWithHealthMonitoring filters.Add(new HandleErrorAttributeWithHealthMonitoring()); } // ... }
2. Add the HandleErrorAttributeWithHealthMonitoring class:
public class HandleErrorAttributeWithHealthMonitoring : HandleErrorAttribute { public override void OnException(ExceptionContext context) { base.OnException(context); // Raise the error to health monitoring new MyRequestErrorWebEvent("An unhandled request exception has occurred", context.Exception).Raise(); } } public class MyRequestErrorWebEvent : WebRequestErrorEvent { public const int CustomEventCode = 100801; public MyRequestErrorWebEvent(string msg, Exception e) : base(msg, null, CustomEventCode, e) { } }
For more information, see http://weblogs.asp.net/awilinsk/archive/2008/12/11/handleerrorattribute-and-health-monitoring.aspx.
For WCF applications, enable unhandled exception logging
See this article for more information: https://leansentry.zendesk.com/entries/27297257-Enable-WCF-detailed-error-tracking.
If you have any questions about this, email us and we'll be glad to help.
Comments
0 comments
Article is closed for comments.