读Log文件,当文件大小变化时打开文件,从新添加的几行读
来源:互联网 发布:网络空间安全期刊 编辑:程序博客网 时间:2024/06/06 09:24
全局变量
int CurrentLine = 0;
start = new FileInfo(chewuserverlogsAppPath);
startSize = start.Length;
1、启一个现程
public void ListenFileChange()
{int line = 0;
this.StartLine = ReadLog(line); //读原来文件行
Thread thread = new Thread(new ThreadStart(FChanged));
thread.Start();
}
private void FChanged()
{
long endSize = 0;
while (true)
{
end = new FileInfo(AppPath);
endSize = end.Length;
if (endSize != startSize)
{
EndLine = ReadLog(CurrentLine);
startSize = endSize;
}
}
Thread.Sleep(1000);
}
}
2、读log
public List<string> ReadLog(int currentLine)
{
//读取logs文件
int current_line = 0;
FileStream fs = new FileStream(AppPath, FileMode.OpenOrCreate, FileAccess.Read,FileShare.ReadWrite);
StreamReader sr = new StreamReader(fs);
string srline = sr.ReadToEnd();
string[] arraystr = Regex.Split(srline, "\r\n");
List<string> list = new List<string>();
current_line = currentLine;
while (srline != null && current_line < arraystr.Length)
{
list.Add(arraystr[current_line]);
current_line++;
}
CurrentLine = current_line;
fs.Close();
sr.Close();
return list;
}
- 读Log文件,当文件大小变化时打开文件,从新添加的几行读
- fork & exec时打开文件的变化
- C语言 打开文件时改变文件大小
- 不打开文件求文件大小
- 编写程序显示给定的文件大小,当文件不存在时显示出错信息。
- EXCEL 2010设置每次打开文件都从新窗口打开
- vc6的文件添加,文件打开出问题
- Log4Net 的Log文件添加行号
- 监控log文件变化进行读出变化的内容供分析的源码类
- log文件owener自动变化问题
- 打开项目中添加的EXCEL文件
- C#控制台基础 打开指定的文件夹后,第一眼看到的文件的名称,文件大小
- 当编译VC项目时提示不能打开生成的动态库.dll或者.exe文件
- core文件大小,进程能打开的文件数大小的设置
- android杂记--C++文件的添加log方法
- 当打开一个.h或.cpp文件时, Solution Explorer就自动展开文件所在的目录
- 当打开一个.h或.cpp文件时, Solution Explorer就自动展开文件所在的目录
- eclipse打开错误,提示查看Log文件
- unity3d 性能优化技巧(持续更新)
- gradle 多flavors生成apk
- Java多线程八
- 200. Number of Islands
- iOS 中 set,get方法
- 读Log文件,当文件大小变化时打开文件,从新添加的几行读
- TC SRM 683 div2 MoveStonesEasy 贪心
- DSB,ISB,DMB指令
- UVA Find the Permutations 11077 (DP&置换群)
- 各位有谁知道COEP这表是干什么的吗?
- 客户端使用Socket与服务器通信
- C#如何使用异步编程
- 线程池ThreadPoolExecutor使用简介
- Mysql/SQLServer数据类型与java基本数据类型的对应