IIS Log Parser Using C# and Saved In Database

Pada posting berjudul "IIS Log Parser Using C# and Saved In Database" kali ini penulis akan memberikan sample program untuk melakukan parsing IIS Log ke dalam database SQL Server.

Fungsi IIS Log sendiri untuk mencatat lalu lintas apa saja yang terjadi di dalam web server sehingga kita dapat menganalisa utilisasi dari aplikasi maupun respond time dari aplikasi terhadap request yang diminta oleh client.

Source code asli dari sample yanga akan saya berikan diambil dari situs : https://www.codeproject.com/Articles/18749/LogParser-DataProvider-for-ADO-NET.
Pada posting ini source code tersebut telah dimodifikasi sehingga hasil parsing dapat langsung disimpan kedalam database sehingga lebih mudah untuk diolah untuk laporan analisa.

Penjelasan Singkat

Hal yang pertama kita perlukan adalah membuat database untuk menyimpan hasil parsing IIS Log. Dibawah ini contoh script dan tampilan database yang penulis gunakan untuk menampung hasil parsing.


Contoh Struktur Table

USE [master]
GO
CREATE DATABASE [IISLOG]
 CONTAINMENT = NONE
 ON  PRIMARY
( NAME = N'IISLOG', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\IISLOG.mdf' , SIZE = 4096KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
 LOG ON
( NAME = N'IISLOG_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\IISLOG_log.ldf' , SIZE = 9216KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO
ALTER DATABASE [IISLOG] SET COMPATIBILITY_LEVEL = 110
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [IISLOG].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO
ALTER DATABASE [IISLOG] SET ANSI_NULL_DEFAULT OFF
GO
ALTER DATABASE [IISLOG] SET ANSI_NULLS OFF
GO
ALTER DATABASE [IISLOG] SET ANSI_PADDING OFF
GO
ALTER DATABASE [IISLOG] SET ANSI_WARNINGS OFF
GO
ALTER DATABASE [IISLOG] SET ARITHABORT OFF
GO
ALTER DATABASE [IISLOG] SET AUTO_CLOSE OFF
GO
ALTER DATABASE [IISLOG] SET AUTO_SHRINK OFF
GO
ALTER DATABASE [IISLOG] SET AUTO_UPDATE_STATISTICS ON
GO
ALTER DATABASE [IISLOG] SET CURSOR_CLOSE_ON_COMMIT OFF
GO
ALTER DATABASE [IISLOG] SET CURSOR_DEFAULT  GLOBAL
GO
ALTER DATABASE [IISLOG] SET CONCAT_NULL_YIELDS_NULL OFF
GO
ALTER DATABASE [IISLOG] SET NUMERIC_ROUNDABORT OFF
GO
ALTER DATABASE [IISLOG] SET QUOTED_IDENTIFIER OFF
GO
ALTER DATABASE [IISLOG] SET RECURSIVE_TRIGGERS OFF
GO
ALTER DATABASE [IISLOG] SET  DISABLE_BROKER
GO
ALTER DATABASE [IISLOG] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
GO
ALTER DATABASE [IISLOG] SET DATE_CORRELATION_OPTIMIZATION OFF
GO
ALTER DATABASE [IISLOG] SET TRUSTWORTHY OFF
GO
ALTER DATABASE [IISLOG] SET ALLOW_SNAPSHOT_ISOLATION OFF
GO
ALTER DATABASE [IISLOG] SET PARAMETERIZATION SIMPLE
GO
ALTER DATABASE [IISLOG] SET READ_COMMITTED_SNAPSHOT OFF
GO
ALTER DATABASE [IISLOG] SET HONOR_BROKER_PRIORITY OFF
GO
ALTER DATABASE [IISLOG] SET RECOVERY FULL
GO
ALTER DATABASE [IISLOG] SET  MULTI_USER
GO
ALTER DATABASE [IISLOG] SET PAGE_VERIFY CHECKSUM 
GO
ALTER DATABASE [IISLOG] SET DB_CHAINING OFF
GO
ALTER DATABASE [IISLOG] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF )
GO
ALTER DATABASE [IISLOG] SET TARGET_RECOVERY_TIME = 0 SECONDS
GO
EXEC sys.sp_db_vardecimal_storage_format N'IISLOG', N'ON'
GO
USE [IISLOG]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[IISLog](
    [LogFilename] [varchar](255) NOT NULL,
    [RowNumber] [int] NOT NULL,
    [EntryDate] [date] NULL,
    [EntryTime] [datetime] NOT NULL,
    [ServerName] [varchar](255) NOT NULL,
    [ServerIpAddress] [varchar](255) NOT NULL,
    [Method] [varchar](255) NOT NULL,
    [Uri] [varchar](255) NOT NULL,
    [UriQuery] [varchar](255) NULL,
    [Port] [int] NOT NULL,
    [Username] [varchar](255) NULL,
    [ClientIpAddress] [varchar](255) NOT NULL,
    [UserAgent] [varchar](255) NOT NULL,
    [Cookie] [varchar](255) NULL,
    [Hostname] [varchar](255) NOT NULL,
    [HttpStatus] [int] NOT NULL,
    [BytesFromServerToClient] [int] NOT NULL,
    [BytesFromClientToServer] [int] NOT NULL,
    [TimeTaken] [int] NOT NULL,
    [LoadDate] [datetime] NULL
) ON [PRIMARY]
GO

CREATE CLUSTERED INDEX [ClusteredIndex-RowNumber-LoadDate] ON [dbo].[IISLog]
(
    [RowNumber] ASC,
    [LoadDate] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
USE [master]
GO
ALTER DATABASE [IISLOG] SET  READ_WRITE
GO

Hasil dari parsing yang telah tersimpan di dalam database akan terlihat seperti gambar berikut ini :

IIS Log Parser Using C# and Saved In Database


Sample code IIS Log Parsing dapat diunduh pada link download berikut ini.

Semoga posting tentang "IIS Log Parser Using C# and Saved In Database" diatas dapat bermanfaat.



Salam,

Popular posts from this blog

K2 Error Value Cannot Be Null. Parameter Name: s In SmartView and SmartObject

Cara inject USB 3.0 Driver pada instalasi Windows - How to Inject USB 3.0 Driver in Windows 7

Pentaho Spoon Error : "Could Not Create The Java Virtual Machine"