O'Reilly logo

Instant Nancy Web Development by Christian Horsdal

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Handling cross-cutting concerns – Before, After, and Error hooks (Intermediate)

In this recipe, we take a look at how to handle cross cutting concerns in our Nancy application. Specifically, we will see the following:

  • Use the before and after hooks to log every incoming request and to log all the status codes of all responses
  • Use the error hook to log all unhandled exception from our modules

Both of these are achieved via the application wide hooks; that is, they work for all requests. There are similar module specific hooks; for example, they work only on requests handled by that module.

We will use the NLog (http://nlog-project.org) logging library in this recipe but this could be any logging library.

Getting ready

We will work on the code done so ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required