Saturday, May 21, 2011

Using Log Parser with SharePoint

What is Log parser? Well, as per Microsoft's definition: Log parser is a powerful, versatile tool that provides universal query access to text-based data such as log files, XML files and CSV files, as well as key data sources on the Windows operating system such as the Event Log, the Registry, the file system, and Active Directory.

With Log parser, we can analyse the IIS Logs and get info like:
     • Number of unique users
     • Top IP hits
     • What referrers were sending people to my site
     • Which pages were most popular
     • How much data out
    • Which HTTP status codes are being generated , etc

say for example, I would like to retrieve the user information in CSV format for my SharePoint site, from Multiple WFEs, I can do by the following query:

LogParser -i:W3C "SELECT distinct TO_LOWERCASE(cs-username) As UserName INTO 3319_User_names.csv FROM <IIS LOG FOLDER>,<IS LOG FOLDER of another server> WHERE UserName Is Not Null" -o:CSV

IIS LOG FOLDER: Its a folder where IIS Logs are stored. you can retrieve the from Multiple servers too. e.g. //mywfe2/D$/Logs/IIS/MyWebApp/W3SVC1126740424/*

Query to Find When a SharePoint Site was accessed last time:
Logparser -i:iisw3c "SELECT Date, cs-username, cs-uri-stem, COUNT (*) FROM c:\WINDOWS\system32\LogFiles\W3SVC2133324272\*.log WHERE cs-username <> NULL AND cs-uri-stem LIKE '/sites/Sales/%' GROUP BY DATE,cs-username,cs-uri-stem" -q:Off -e:1 -o:datagrid 

Query to find Most Accessed Site URLs:
@path=C:\Program Files\Log Parser 2.2\

LogParser -i:W3C "SELECT TOP 50 cs-uri-stem as Url, COUNT(*) As Hits INTO MaxHits.csv FROM C:\WINDOWS\system32\LogFiles\W3SVC1\* GROUP BY cs-uri-stem ORDER By Hits DESC" -o:CSV

Query to get user count of SharePoint Intranet sites with their Hit counts:

@path=C:\Program Files (x86)\Log Parser 2.2\

LogParser -i:W3C "SELECT TO_LOWERCASE(cs-username) As UserName, count(*) as [Total Hits] INTO PortalUsersList.csv FROM C:\WINDOWS\system32\LogFiles\W3SVC2133324272\*, \\WFE02\c$\WINDOWS\system32\LogFiles\W3SVC2133324272\*, \\WFE03\c$\WINDOWS\system32\LogFiles\W3SVC2133324272\* WHERE date > '2010-12-31' AND cs-username Is Not Null group by TO_LOWERCASE(cs-username)" -o:CSV

Log Parser Query to get Users & Hits on a Sub-Site: /operations/partners/salesforce/
@path=C:\Program Files (x86)\Log Parser 2.2\

LogParser -i:W3C "SELECT cs-uri-stem, cs-username, count(*) as [Total Hits] INTO SubsiteHits.csv FROM \\WFE01\C$\inetpub\logs\LogFiles\W3SVC274624414\*, \\WFE02\C$\inetpub\logs\LogFiles\W3SVC274624414\* WHERE cs-uri-stem like '%%/operations/partners/salesforce%%' AND date > '2014-04-18' and cs-username <> 'Global\svcSPSearch' AND cs-username <> NULL group by cs-uri-stem, cs-username " -o:CSV


Log parser is a command line tool, you can the Log Parser Lizard GUI tool:

More info on using Log parser tool:

Log Parser 2.2 download URL:

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...