Did you ever want to know what CAML queries are executed by SharePoint Server?
Well, for troubleshooting and learning purpose, it is not a bad idea. After all, SQL Profiler has been helping us troubleshoot a lot of issues.
There may be products out there but I figured out a way to do it without spending extra bucks! And here it is…
Following facts helped me think about the solution:
1) SharePoint’s code does a very good job at logging everything it does and everything it encounters (if you are lucky enough to figure it out). The challenge is to figure out under what area and category CAML queries are logged (if at all being logged). Once this is figured out, watching it real time is easy, see next step
2) The ULS Viewer is the tool which allows you to filter the events that you want to watch and watch them real time as they are logged to ULS logs by SharePoint code.
Follow the steps below to see it in action:
1. Go to Central Administration-> Monitoring –> Configure Diagnostic Logging.
Expand the SharePoint Foundation Area and check Monitoring and select Verbose level (selecting anything else would not work)
2. I did IIS Reset after changing the setting. Not sure if that is required though.
3. Download and run ULS Viewer. Select ULS Logs as your data source as shown below:
4. Now modify the Filter (Access it from Edit –> Modify Filter) to filter messages that contains the CAML word as shown below:
And that should be it! Go to any Lists and select a view, since views use CAML behind the scene, you should see and entry and watch the CAML that was executed.