Sunday, 5 August 2012

SharePoint 2010 : ULS Logging

“How do you do logging in your application?” This is the question many people asks
me. Hence thought to put it into a post and redirect them to it…

SharePoint
2010 Guidance has one approach to log the exception into ULS logs…however
approach needs a farm scoped feature to register ULS Categories and Areas. Many
times, creating farm level feature is not possible due to the restrictions applied
by Farm Administrators.

Figure 1 : Area and Category in ULS log
file

There is another approach mentioned by my favorite MVP
Waldek Mastykarz in his blog post Logging to ULS inSharePoint 2010. This approach does not need any feature for registering
the ULS Category and Areas.

Well, I use Waldek’s approach with little bit of tweaks so that I can to log
Exceptions, Information and Warnings. I also use Enums for defining Categories
which represents particular module so that I would come to know in which module
exceptions has occurred. I use Application name as Area and Module names as Categories....