IIS6.0日志文件分析代码_1生成访问字段记录到数组中,只能处理小体积的LOG文件.系统构思有些欠缺.比如文本文件读取到100行好象就CPU占用率很高.然后程序卡死.升级可考虑用文本文件分割方法设计.升级可考虑直接读一条记录马上写到数据里.
//添加数据库文件IO引用
using System.IO;
using System.Text;
using System.Data;
using System.Data.SqlClient;
//窗体变量定义
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private string BinaryFileType;
private string BinaryFilePath;
private int BinaryFileLength;
private int totalLogFileLine=0;
private static int splitLineNumber=0;
private void button1_Click(object sender, System.EventArgs e)
{
this.button1.Enabled=false;
//调用打开文件对话框获取要打开的文件WORD文件,RTF文件,文本文件路径名称
OpenFileDialog opd = new OpenFileDialog();
opd.InitialDirectory = @"C:/WINDOWS/system32/LogFiles";
opd.Filter = "日志文档(*.log)|*.log|Word文档(*.doc)|*.doc|文本文档(*.txt)|*.txt|RTF文档(*.rtf)|*.rtf|所有文档(*.*)|*.*";
opd.FilterIndex = 1;
if (opd.ShowDialog() == DialogResult.OK && opd.FileName.Length > 0)
{
try
{
BinaryFileType=opd.FileName.Substring(opd.FileName.LastIndexOf(".")+1).ToUpper();
BinaryFilePath=opd.FileName;
FileStream fs = new FileStream(opd.FileName, FileMode.OpenOrCreate, FileAccess.Read);
BinaryFileLength=(int)fs.Length;
StreamReader myStreamReader=new StreamReader(fs);//使用StreamReader类来读取文件
myStreamReader.BaseStream.Seek(0,SeekOrigin.Begin);//从数据流中读取每一行,直到文件的最后一行,并在richTextBox1中显示出内容
this.richTextBox1.Text="";
string strLine=myStreamReader.ReadLine();
int LineSoftware=0;
int LineVersion=0;
int LineDate=0;
int LineFields=0;
int LineContent=0;
ArrayList MySoftwareArray=new ArrayList();
ArrayList MyVersionArray=new ArrayList();
ArrayList MyDateArray=new ArrayList();
ArrayList MyFieldsArray=new ArrayList();
ArrayList MyContentArray=new ArrayList();
ArrayList MyLineArray=new ArrayList();
//定义日志数据表格
DataTable MyLogTable = new DataTable();
MyLogTable.Columns.Add(new DataColumn("LogSoftware",typeof(string)));
MyLogTable.Columns.Add(new DataColumn("LogVersion",typeof(string)));
MyLogTable.Columns.Add(new DataColumn("LogDate",typeof(string)));
MyLogTable.Columns.Add(new DataColumn("LogFields",typeof(string)));
MyLogTable.Columns.Add(new DataColumn("LogContent",typeof(string)));
while(strLine!=null)
{
this.richTextBox1.Text+= strLine+"/n";
if(strLine.Substring(0,10)=="#Software:")
{
LineSoftware+=1;
MySoftwareArray.Add(strLine.Substring(10,strLine.Length-10));
}
else
{
if(strLine.Substring(0,9)=="#Version:")
{
LineVersion+=1;
MyVersionArray.Add(strLine.Substring(9,strLine.Length-9));
}
else
{
if(strLine.Substring(0,6)=="#Date:")
{
LineDate+=1;
MyDateArray.Add(strLine.Substring(6,strLine.Length-6));
}
else
{
if(strLine.Substring(0,8)=="#Fields:")
{
LineFields+=1;
MyFieldsArray.Add(strLine.Substring(8,strLine.Length-8));
}
else
{
MyContentArray.Add(strLine);
DataRow newLogRow=MyLogTable.NewRow();
newLogRow["LogSoftware"]=MySoftwareArray[splitLineNumber].ToString();
newLogRow["LogVersion"]=MyVersionArray[splitLineNumber].ToString();
newLogRow["LogDate"]=MyDateArray[splitLineNumber].ToString();
newLogRow["LogFields"]=MyFieldsArray[splitLineNumber].ToString();
newLogRow["LogContent"]=MyContentArray[LineContent].ToString();
MyLogTable.Rows.Add(newLogRow);
if(splitLineNumber!=LineSoftware)
{
MyLineArray.Add(LineContent);
}
else
{
splitLineNumber+=1;
}
LineContent+=1;
//arr[LineContent]=new LogRsData(strLine, "Les Paul", LineContent);
}
}
}
}
strLine=myStreamReader.ReadLine();
totalLogFileLine+=1;
}
myStreamReader.Close();//关闭此StreamReader对象
fs.Close();
this.richTextBox1.Text+= ":"+ LineSoftware+":"+LineVersion+":"+LineDate+":"+LineFields+":"+LineContent+"/n";
this.dataGrid1.DataSource =MyLogTable;
this.textBox2.Text=BinaryFilePath;
this.textBox3.Text="0";
this.textBox4.Text=totalLogFileLine.ToString();
this.textBox5.Text=BinaryFileLength.ToString();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message,"打开文件错误");
}
}
this.button1.Enabled=true;
}
分享到:
相关推荐
IISADMIN.MO_,IIS6.CAB,IIS.DL_,IIS.IN_,IIS.MS_,IISADMIN.DL_,IISADMIN.MF_
IIS.DL_和IIS.IN_ 文件下载
IISRG.CH_,IISFTP.VB_,IISFTPDR.VB_,IISLOG.DL_,IISMAP.DL_,IISMUI.DL_,IISNTS.CH_,IISPWCHG.DL_,IISRES.DL_,IISRESET.EX_
,HTTPAPI.DL_,HTTPEXT.DL_,HTTPMB51.DL_,HTTPMIB.DL_,HTTPOD51.DL_,HTTPODBC.DL_,IASPERF.DL_,IASPERF.H_,IASPERF.IN_,IASPOLCY.DL_,IEWEBHLP.CH_,IIRSP.SY_,IIS.DL_,IIS.IN_,IIS.MS_,IIS6.CAB,iisadmin.dll,IIS...
XP家庭版可以安装IIS,但是需要有WIN2000的IIS文件:IIS.DL_和IIS.IN_。 具体方法可以到网上搜索,但是这两个文件必须要有。
INETINFO.EX_,IISVDIR.VB_,IISW3ADM.DL_,IISWEB.VB_,IISWMI.DL_,IISWMI.MF_,IISWMI.MO_,IMS.CAB
Windows 2000 Professional的iis.dl_和iis.in_
iis安装缺少的文件,iis.dl_和iis.in_
安装IIS所需文件IIS.inf文件.inf文件提供下载
HTTPOD51.DL_ IIS6.CAB IIRSP.SY_ HTTPODBC.DL_ IIS.DL_ IIS.IN_ IIS.MS_ IISAPP.VB_ IISADMIN.DL_ IIS_chaccess.vbs IISBACK.VB_ IISCFG.DL_ IISCHE51.DL_ IISCLEX4.DL_ IISCNFG.VB_ IISCRMAP.DL_ IISDG.CH_ IISEXT...
提取出的文件目录表,仅供参考: ACHG.AS_ ACWEBSVC.DL_ ADMWPROX.DL_ ADROT.DL_ ADSIIS.DL_ ADSUTIL.VB_ AEXP2B.AS_ AEXP4B.AS_ APPS.CH_ APPS.IN_ APPSRV.MS_ APPSTAR2.AN_ APPSTAR3.AN_ APPSTART.AN_ APPS_SP.CH...
IIS5.1 ......\200504091iis51.rar ......\ADAPTEC.HTM ......\ADAPTEC.TXT ......\ADCJAVAS.IN_ ......\ADCVBS.IN_ ......\ADDREMOV.CH_ ......\ADE.HL_ ......\ADESKERR.HT_ ......\ADMEXS.DL_ ......\...
IIS_contftp.vbs IIS_contftp.vbs IIS_contftp.vbs IIS_contftp.vbs IIS_contftp.vbs
DLL文件,在安装IIS时用得到,挺好用的一个东西
xp安装iis6时用到的文件IIS_clusweb.vbs文件,IIS_iis_switch.bat文件,IIS_iis_switch.vbs文件,IIS_text.asp文件
IIS.DL_ IIS.DL_
( iisexpress_1_11_x86_zh-CN.msi )
安装IIS时,会少部分文件 文件包含文件有: EXCH_adsiisex.dll EXCH_aqadmin.dll EXCH_aqueue.dll EXCH_fcachdll.dll EXCH_mail.chm EXCH_mailmsg.dll EXCH_ntfsdrct.h EXCH_ntfsdrct.ini EXCH_ntfsdrv.dll EXCH_...
windows XP home版安装IIS方法