Configuring Logging in SharePoint Application Pages

In my previous post I showed how my simple, but highly effective approach to logging can be used with ASP.NET Web applications — including Microsoft Office SharePoint Server (MOSS) and Windows SharePoint Services (WSS).

Note that SharePoint application (i.e. _layouts) pages are served from a different virtual directory than content pages within the Web application. Consequently, in order to view log messages when, for example, activating a feature (e.g. using http://fabrikam/en-US/Products/_layouts/ManageFeatures.aspx) the System.Web.WebPageTraceListener must be specified in the Web.config file within the following folder:

%ProgramFiles%\Common Files\Microsoft Shared\Web Server Extensions\12\template\layouts

Also be sure to enable tracing using the <trace> element within <system.web> in that Web.config file, as shown in my previous post.

Now you can easily view log messages from a feature receiver that uses the custom Logger class regardless of whether the feature is “activated” via Site Settings, through stsadm.exe, or from within Visual Studio via a unit test.