A righteous hack – designing logging as a service. On my latest project I made sure to set up logging with log4net straight from the beginning. I wrote a custom logger which sends trace messages to the database per user. Then, I made sure the User object has a property to turn debug logging on or off per user.

So now, when a user says they have a problem, or when we get an application error email (you have your apps send mails to you when there is a fatal error, right?) we turn on debug logging for that user, and follow the trace when they go through the system next.

From the user’s point of view, all of this is completely transparent. It is almost as useful as Windows Error Reporting, but for a web app. Surprisingly, people do try to do the same thing over and over again if it doesn’t work the first time. Interestingly this actually helps them help us. Although I am toying with the idea of setting up a rule in the error httpmodule to automatically turn on debug logging for the remainder of that login session.