如果你不想导入到数据库中,可以试试这个
http://www.cnblogs.com/downmoon/archive/2009/09/02/1558409.html
/// <summary> /// 读取文件内容 /// </summary> /// <param name="htmlPath"></param> /// <returns></returns> public List<IISLog_Status> ReadLog(string logPath, int serviceID, string logfileName) { List<IISLog_Status> listAnalysisLog = new List<IISLog_Status>(); if (File.Exists(logPath)) { StreamReader objReader = new StreamReader(logPath); string sLine = ""; while (sLine != null) { sLine = objReader.ReadLine(); if (sLine != null) { if (logStatus(sLine)) { try { listAnalysisLog = AnalysisLog(listAnalysisLog, sLine, serviceID, logfileName); } catch(Exception ex) { AddLog.AddMsgLog(AddLog.LogType.Error, "日志文件处理错误!", ex.Message, ex.StackTrace.ToString()); } } } } objReader.Close(); } return listAnalysisLog; }
这种东西最好能建立对应索引,否则怎么查都很慢.