Logging in ASP.NET - Web Services (contd.)

· Read in about 2 min · (255 words) ·

I’m almost through with a decent logging implementation for a Web service running under Windows Sharepoint services. Here are some hard earned lessons:

  1. I could not use Global.asax for a sharepoint hosted web service. The Sharepoint web services Global.asax derives from stssoap and when I included the code in a C# script block, the code never got invoked.

  2. Also, the concept of an application is not useful in the case of web service - since a single web might be used to host multiple services. So, now, I’ve moved all the Log4Net initialization code to the ASMX code behind ctor. I’ve also got a SetContext() method that sets the user name, application (service) name. I’m also mulling about including the last few characters from the session key - for cases where the same user is logged on from multiple machines.

  3. I need to do some more fine tuning - like enabling the connection pooling for the log4net connection string.

  4. Another great lesson learned - and this is for all the times when you’ve got all the bits of log4net up and running and yet can’t seem to get the logs…​Use the log4net Debug release with the DbgViewutility from sysinternals. Log4net fails silently on errors and just doesn’t give you a clue as to what happened. For all those times when something utterly silly like a typo in your config brings all your logging to a standstill, keep DbgView running side by side. If Log4net hits a problem, it’ll get logged in the dbgview console. :)