The Quick Start Guide to using Gibraltar in ASP.NET MVC

The first step in using Gibraltar within an MVC site is to install the agent. The easiest way to do this is via NuGet, either using the interface or the Package Manager Console; in either case the package you need is Gibraltar.Agent. Once installed you can start using the logging features right away using the Gibraltar.Agent.Log class. For example, to log a warning about account creation failures, you could add the following to the RegisterAccount action:

if (createStatus == MembershipCreateStatus.Success)
    FormsAuthentication.SetAuthCookie(model.UserName, false);
    return RedirectToAction("Index", "Home");
    ModelState.AddModelError("", ErrorCodeToString(createStatus));
    Gibraltar.Agent.Log.Warning("Security", "Membership Creation Failure",
        "Failed to create account '{0}' Status: {1}",
        model.UserName, createStatus.ToString());

The Log class has other methods, such as Information, Error and Warning, all of which allow you to log message details and exceptions. These show up in Gibraltar Analyst so you can easily filter and group by the severity of the message. This, of course, is manual logging of messages, but you may want automatic logging of things such as exceptions. In this case you can use the standard MVC attribute system; you first create an attribute that inherits from HandleErrorAttribute, and within the OnException method you log your exception details to Gibraltar. Then you add this attribute to the filters collection in the RegisterGlobalFilters method in Global.asax. For a video to show you how to do this, see I See MVC.

You can find out more about simple logging in the Gibraltar help pages at

Since we’re now getting close to Christmas, what feature is on your Gibraltar Software Christmas List?

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