Click here to Skip to main content
15,861,172 members
Articles / Database Development / SQL Server / SQL Server 2008

SharePoint 2010 Logging Database

Rate me:
Please Sign up or sign in to vote.
4.75/5 (6 votes)
6 Apr 2010CPOL4 min read 91.9K   16   12
Four reasons to directly query SharePoint logging database

Introduction

Remember my post “Five reasons not to directly query SharePoint databases”? I have cautioned you more than once throughout it NOT to directly query SharePoint databases and I have mentioned its disadvantages and problems. If you haven’t read this post, I would encourage you to do that before carrying on.

I’m not contradicting myself! The first post was all about SharePoint 2007 but now I’m talking about the new and the amazing 2010 version of SharePoint.

So you might be asking “What the hell is SharePoint Logging Database?” Good question!

To answer you, please fire up the SQL Management Studio, and expand your databases. You’ll notice a new one named WSS_Logging.

image

SharePoint 2010 keeps track of everything it does by logging into the WSS_Logging database. It aggregates all of the raw logging data accumulated in the text files under the 14 hive and imports it into this wonderful logging database. This is the ONLY database in SharePoint that Microsoft will be happy to let the developers directly read, query and build reports against it. There is a bunch of useful views at your disposal, the one that I will show you now is the “RequestUsage” View.

Every time a user visit generates a page request, a record is inserted into one of the partitioned tables in this database and the “RequestUsage” view is kind enough to union all the data in the partitioned tables and presents it to you to consume in your custom solutions (Web Parts, Reports, Application Pages,…). An example is shown below:

clip_image003

Let’s dive a little bit deeper to see what happens behind the scenes and where this data comes from.

  1. Navigate SharePoint 2010 Central Administration > Monitoring > Configure usage and health data collection.

    clip_image007

  2. Now let’s configure the data collection by specifying what events to log to the text files under the 14 hive. Use the snapshots below to configure your own SharePoint system.

    clip_image009

    clip_image011

  3. Did you notice the “Log Collection Schedule” section? This implies that there is a timer job that collects the log files located under the 14 hive and copies the events you specify into your logging database which can be employed later for reporting purposes. You can even schedule this timer job based on the load patterns of your server as you will see in the next step.
  4. I have opened up my favorite troubleshooting tool (SharePoint Manager 2010) to track this job. As you can see in the figure below, I have configured the “Microsoft SharePoint Foundation Usage Data Import” job from the central administration to run every minute.

    immediately_Start_A_Timer_job

    clip_image002

  5. Out of curiosity, I have decided to use .NET Reflector to check out how this timer job works, I have noticed two things.

    clip_image005

    The first one is that the Job lock type specified in the constructor is SPJobLockType.None which instructs the Timer Service to run this job on all the Web Front Ends in the farm, this makes sense!

    The difference between the Job and the None LockTypes is that the Job LockType ensures that the timer job only runs on one server but the None ensures that the job runs on every server.

    image

    The second one is the ImportUsageData() Method in the execute method which is called when the timer job runs, this method is responsible for copying the events from the log files into your logging database. You can further expand this method if you need to know more.

So, what are those four benefits I’m talking about ?

  1. It’s fully supported by Microsoft to directly read, query and build reports from the logging database. Third party applications can even write their data back to it.
  2. It’s enabled by default on all the SharePoint deployments.
  3. The retention policy is customizable allowing you to manage how many data you want to accumulate (14 days by default, but this could be modified using PowerShell)
  4. The Schema will be documented which will definitely facilitate its usage.

I would also like to point out that the Logging Database forms the basis for a lot of usage and health reporting. For example, the Web Analytics features heavily rely on it as it takes data out, does some additional processing on it, puts it into the analytics database and reports are generated based on that.

History

  • 6th April, 2010: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Egypt Egypt
Ayman El-Hattab is a Regional Technology Solution Professional focusing on helping software professionals and organizations build better SharePoint Solutions using Microsoft Application Lifecycle Management (ALM) technologies and tools. Ayman has been in this role since 2010 and has presented at many conferences all over the Middle East & Africa about ALM, SharePoint, C#, asp.net and Business Intelligence technologies. Ayman is also a Microsoft Most Valuable Professional [SharePoint MVP] , ALM Ranger, published author and an enthusiastic speaker who enjoys working with the online and offline developer communities all over the world. Ayman is the founder of MEA ALM Community & SharePoint4Arabs, community lead at Egypt SharePoint User Group and an organizer of several SharePoint Saturday events. Outside of work, Ayman can be found watching soccer games, playing xbox or watching documentary movies.

Comments and Discussions

 
Generalquestion Pin
ace2k@mail.ru22-Jun-10 8:02
ace2k@mail.ru22-Jun-10 8:02 
GeneralRe: question Pin
AmXAML23-Feb-11 2:11
AmXAML23-Feb-11 2:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.