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

Loupe 4.5 Released with New Log Viewer for Web

Rapidly diagnose each error in any .NET application with our new Web Log Viewer and Exception root cause analysis, new in Loupe 4.5. New integration with Azure Service Bus and Azure Search enables full Loupe functionality without any Virtual Servers in Azure. Read more

Cloudflare Vulnerability Does Not Affect Us

The recently reported Cloudflare vulnerability where fragments of secure, encrypted user data could be exposed to a third party does not affect Gibraltar Software even though we use Cloudflare because we only route static content through the Cloudflare proxy for acceleration. Read more

We're out of our Last Data Center

Back in January of 2016 we decided to completely transition out of our data centers and into the cloud. On Sunday we finally shut down the last cluster of our hardware. Read more for how we did it and whether we would do it all over again if we had... Read more

Rock solid centralized .NET logging

Unlimited applications, unlimited errors, starting at $25/month