However the code used for this logging is embed into the main project and not easily portable, I wanted to make a assembly that captured this functionality so I could easily drop it into the next project. So we created StickyBeak.
StickyBeak is a logging tool for asp.net websites written in c# and currently requires the NLog logging library to run. StickyBeak’s purpose is to log each request to your web server and also provide a easy interface to view these requests.
Looking at these logged requests is extremely useful when you are trying to find the cause of an exception or even more useful when you are trying to recover some lost data because of an exception.
StickyBeak works as an HttpModule and logs the raw request data into a log file using Nlog. The information recorded for the requests includes, date, http method, url, User.Identity.Name, IP Address, unique session Id, unique browser Id, header values, querystring values, posted form values and cookie values.
Below is a screenshot of the admin viewing tool, which lets you see the logged activity on your site.
How it worksStickyBeak runs as a HttpModule, each time a request is processed by .net the module creates a new RequestLog object and populates all the data using the current request. The RequestLog object is then passed to the LogRepository which saves the Requestlog object.
Currently there is only one LogRepository, this repository uses NLog. The NLogRepository writes the LogRequest object out to the log files in a custom format. The NLogRepository can also read LogRequest objects for viewing using the admin interface.
Configuration Needed For StickyBeak To Work
- You need a reference to the StickyBeak and NLog assemblies contained in the binary zip file distribution on CodePlex
- Configure the StickyBeak HttpModule
- Configure the handler (to display admin interface). The configuration below also secures the handler you may wish to remove this for testing.
- Configure NLog to record the logging information that is record by StickBeak
- You can also optionally configure exclusions for StickyBeak. For example you could exclude all requests to a certain URL, exclude a querystring/form/cookie/header value by key etc. See the sample configuration for more details.