Gibraltar: Get Log Files Immediately When There's a Problem

It’s Day 12 of Advent and time to open up our next treat, today for users of Gibraltar - how to get the details immediately for your applications when there’s a problem.

Most of the time log details don’t need to be collected quickly; it’s better to take an efficient, no impact approach that just gets them to the central location once a day or after the user’s done with the application.  This is the default approach Gibraltar takes, but what about when something just went bad on your production web site?  Clearly we don’t want to wait until tonight to find out about problems happening right now.

To solve this the Gibraltar Agent includes a feature called MessageAlert.  This is an event that is raised in the background when information gets logged with a warning, error, or critical severity.  Keeping with the “first do no harm” approach of Gibraltar the MessageAlert event is raised asynchronously from gathering and recording data so it won’t impact the performance of your application.

If we want to get the details of the current session as quickly as possible when there’s an error all we need to do is tell the Agent to send immediately whenever we see there’s an error.  To do this, just add an event handler to the Log.MessageAlert event, like this:

using Gibraltar.Agent;

public class Global : System.Web.HttpApplication
    protected void Application_Start(object sender, EventArgs e)
        Log.MessageAlert += Log_MessageAlert;
    private void Log_MessageAlert(object sender, LogMessageAlertEventArgs e)
        if (e.TopSeverity <= LogMessageSeverity.Error)
            e.SendSession = true;
            e.MinimumDelay = new TimeSpan(0, 5, 0);

This example is straight from the online documentation.

In this specific example we’ve added the event handler during the Application_Start event of our ASP.NET web site.  The event handler does two things in the case where there is at least one error or critical message in set of messages exposed by the MessageAlert Event:

  1. Tell the agent to send the session right away (e.SendSession = true).  This will start a new, asynchronous background upload of the current session as soon as the event handler returns.
  2. Set the minimum amount of time until the MessageAlert event can be raised again to 5 minutes.  This protects against cases when there are a lot of errors happening on the site in a short period of time.  All of the warning, error, and critical messages will be buffered until the timespan elapses and then the event will be raised again.

And there you have it! You’ll get detailed data right away when there are problems but otherwise the system will run quietly and efficiently.  With all that time you’ve saved on diagnosing problems with Gibraltar, why not spend a few cycles thinking up what else we can do to make your life simpler and Share your ideas with us on Facebook.

Related Posts

PostSharp Diagnostics Now Supports Loupe in the Box

The latest update to PostSharp Diagnostics adds Loupe support, enabling extensive high-performance logging to be added to any .NET application with virtually no code changes. PostSharp even has a great free option for developers that complements Loupe Desktop! Read more

Loupe Agent for .NET Core Now Available

The first release of the Loupe Agent for .NET Core is also our first open source version of the Loupe Agent. This is the first step in our plan to open source the entire Loupe Agent to make it easier for anyone to extend and take advantage of what Loupe... Read more

We've Moved Loupe Service to App.OnLoupe.Com

Loupe Service now has a shorter, direct site name that's faster, anywhere in the world. Just to go App.OnLoupe.Com, the new CDN-accelerated endpoint for the Loupe Service. Your existing Agents and Loupe Desktops are unaffected by this change, but access to the web UI will be redirected to the new... Read more

Rock solid centralized .NET logging

Unlimited applications, unlimited errors, scalable from solo startup to enterprise.