Introduction

I downloaded and tested Gibraltar’s Loupe today and tried to find out what it could add to my application. And because Rachel Hawley asked me t review it, and who am I to refuse her anything.

I already add as much logging to my application as possible because it makes it a lot easier to find bugs and fix them once you go into productions.

But log files can get overwhelming sometimes.

This is where Gibraltar analyst can help.

Installation

I downloaded the 3.0 preview 3. Installation is easy and for now I only installed the desktopversion, but there is also a webversion.

I created a small nancy application with the razor viewengine.

With this as my view.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    <p>Welcome to OUR world!</p>
</body>
</html>

and this as my module.

```vbnet Imports Nancy Imports Gibraltar.Agent

Public Class MainModule Inherits NancyModule

Public Sub New()
    MyBase.Get("/") = Function(parameters)
                          Return View("Main")
                      End Function
End Sub

End Class``` I saved all of it and then went into the loupe desktop.

YOu can now click the big green button that says Add Gribraltar now, point it to your project give it a name and whatnot and voila Gibraltar is there.

Logging

When I run it and go to live sessions.

I can see it.

No idea why it is there twice but you can click one of them.

That’s already more information than we are used to, and we have yet to add logging.

We can do this by using the Gibraltar Agent logging (but we don’t have to).

Just add a line like this.

vbnet MyBase.Get("/") = Function(parameters) Log.TraceInformation("Opening mainmodule") Return View("Main") End Function And next time you run this.

you will see this in your logging session.

You can even click on that link and go to your code.

Or see the code in the tab mainmodule.

That is simple enough.

Exceptions

So how do we deal with exceptions and unhandled exceptions?

Let’s add this code to our module.

vbnet MyBase.Get("/test") = Function(parameters) Try Throw New Exception("some message loup should pick up") Catch ex As Exception Log.TraceError(ex, "something") Return View("Main") End Try End Function MyBase.Get("/test2") = Function(parameters) Throw New Exception("some message loup should pick up") End Function If I now go to the page /test I will see this.

The exception is nicely logged.

But if I go to page /test2, I see nothing.

Gibraltar does not log unhandled exception automatically. We either need ELMAH or we need to add logging to an event somewhere.

Luckily in Nancy this is easy.

Just add a class that implements IErrorhandler and Nancy will do the rest.

```vbnet Imports Nancy Imports Nancy.ErrorHandling Imports Gibraltar.Agent

Public Class Errorhandler Implements IErrorHandler

Public Function HandlesStatusCode(ByVal statusCode As HttpStatusCode, ByVal context As NancyContext) As Boolean Implements IStatusCodeHandler.HandlesStatusCode
    Return statusCode = HttpStatusCode.InternalServerError
End Function

Public Sub Handle(ByVal statusCode As HttpStatusCode, ByVal context As NancyContext) Implements IStatusCodeHandler.Handle
    Dim errorObject As Object
    context.Items.TryGetValue(NancyEngine.ERROR_EXCEPTION, errorObject)
    Dim ex = CType(errorObject, Exception)
    Log.TraceError(ex, "unhandled exception")
End Sub

End Class``` And now we will see our exception.

Conclusion

Loupe was pretty easy to setup and get going. Loupe does however come at a price. Is that price to high? That depends on the value you place on your business.