July 6, 2009

Microsoft LogParser 2.2 Tutorial VIII

Click here to see part VII.

As we come to the end of the logparser tutorials, I wanted to show a basic C# library that can be extended for your needs. This library had a lot of input from various co-workers and blogs. This version of the library is an old stripped down version since the newer version has a lot more code that is propitiatory. I am sure you can extend this and would love to see what you come up with. You can find the codebase for the sample below here.

The main idea of this is to have a simple console application where you can drop a log file and a query and parse it in C# using LogParser. This can be extended to go into an Asp.Net application or a windows GUI for a business user.

Shown below is a snippet of the very basic console.
 class Program
{
static void Main(string[] args)
{
new Program().Run();
}

void Run()
{
W3cView _view = new W3cView();
W3cQueries _queries = new W3cQueries();

//Each query is listed below
_view.CountOfTotalRequests(_queries.CountTotalRequests());
_view.Table(_queries.Top10HitsWithExtensionAspx());
Console.ReadLine();
}
}
The W3C query file which has the list of the sql files that are called looks like this:
 class W3cQueries
{
QueriesHelper queriesHelper = new QueriesHelper();

public int CountTotalRequests()
{
return queriesHelper.GetInt("CountTotalRequests.sql");
}

public LogRecords Top20HitsWithExtensionAspx()
{
return queriesHelper.GetRecords("Top10HitsWithExtensionAspx.sql");
}

//Add more queries
}
I would love to see any extensions that any of you come up with based off this.

No comments:

Post a Comment