如何使用C#和ASP.Net读取日志文件中的行号 [英] How to read line no in log file reading using C# and ASP.Net

查看:73
本文介绍了如何使用C#和ASP.Net读取日志文件中的行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个要求是读取日志文件并将其显示在网格中。但是还需要在该日志文件中读取行号以便为将来的阅读制作书签。但是任何人都可以帮我解决如何在使用C#和ASP.Net阅读日志文件时读取/制作特定行号。还有一件事是如何通过从该日志文件中提供模式匹配/正则表达式来进行过滤。假设我想在该日志文件中获取特定短语如何使用C#,ASP.Net / Jquery获取它。请帮我解决它的紧急情况。

Hi,
I got one requirement for to read a log files and display it in a grid. But there is also a requirement to read line no in that log file to make bookmarks for future reading. But can any one please help me out how to read/make particular line no in that log file reading using C# and ASP.Net. And one more thing how to make filtration for by giving pattern matching/regex from that log file. Suppose i want to get particular phrase in that log file how to get it using C#,ASP.Net/Jquery. Please help me out its urgent.

推荐答案

这是一个问题:因为不知道文件的格式,你不能预测行。



例如文本文件没有行:它们有行终止符,这意味着为了访问行n,你必须读取文件到那一点,计数你去的线路终结器。您可以阅读整个文件,系统会将其转换为行:

That's a problem: because without knowing the format of the file, you can't "predict" lines.

Text files for example don't have lines: they have line terminators, which means that in order to access "line n" you have to read the file up to that point, counting line terminators as you go. You can read teh whole file, and teh system will convert it to lines for you:
string[] lines = File.ReadAllLines(pathToLogFile);

但你不能说

But you can't say

string myLine = MyStream.ReadLine(1237);

因为留下来; t必须是相同的长度。



如果它不是文本文件,它可能有任何内容:这使它更糟糕!我已经看过XML,数据库文件,DOCX,XLS,CSV以及我日常用于日志的专有格式。



所以你需要的第一件事就是看看你的日志,确切地知道它的格式,然后你可以开始寻找识别各个日志条目的方法。但我们不能为你做到这一点!

because liens don;t have to be the same length.

If it isn't a text file, it could have any content: and that make it even worse! I've seen XML, database files, DOCX, XLS, CSV, and loads of proprietary formats used for logs in my time.

So the first thing you need to do is look at your log, and work out exactly what format it has, and then you can start looking at means to identify individual log entries. But we can't do that for you!


这篇关于如何使用C#和ASP.Net读取日志文件中的行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆