Wednesday, October 13, 2010

How to use SharePoint Log Files

How to use SharePoint Log Files

Purpose: SharePoint has a new logging architecture that gives you a much better way of determining issues with your SharePoint farm.
Result: Know how to find and read the SharePoint log files
Task 1 – Turn on verbose and information logging
Open the Central Administration Console
Click “Operations” tab
Under “Logging and Reporting”, click “Diagnostic Logging”

For “Select a category”, select “All”
Under “Least critical event to report to the event log”, select “Information”
Under “Least critical event to report to trace log”, select “Verbose”

Click “Ok”
Task 2 – Review the log file
Open the 12 hive Logs directory (C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\LOGS)
Find the newest log file and open it
Open Microsoft Excel 2007
Copy and paste the data from the log file into Excel
In the menu, click “Data”
In the ribbon, under the “Sort & Filter” jewel, click “Filter”

A majority of your errors will revolve around the w3wp processes, therefore in the second column (process), click the filter dropdown
Uncheck “Select All”
Check all the w3wp.exe processes

Click “Ok”
Review the entries that are present, when any exception occurs across SharePoint it will show up here!
Exercise #2 – Log to SharePoint Log File
Purpose: Learn to append your own messages to the log file
Result: Log entries in the Log files
Task 1 – Create a console application
Open Visual Studio 2005
Create a new console application
Click File->New->Project
Select Console Application
For location, type “c:\Lab Work”
For name, type “Logger”
Click Ok
Add a reference to Microsoft.Office.Server.dll
Right click the project, select “Add Reference”
Click the Browse tab
Browse to c:\program files\common files\microsoft shared\web server extenstions\12\isapi
Select Microsoft.Office.Server.dll
Click Ok
Update the Main code to the following:
using System;using System.Collections.Generic;using System.Text;using Microsoft.Office.Server;namespace ConsoleApplication2{class Program{static void Main(string[] args){try{throw new Exception(“Something bad happend”);}catch (Exception ex){Microsoft.Office.Server.Diagnostics.PortalLog.LogString(“This was a bad one…”, null);}}}}
Run the application
Open the log files, find your log entry