Click here to Skip to main content
15,899,474 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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.
Posted
Comments
Sergey Alexandrovich Kryukov 6-Mar-15 11:02am    
It depends on what you use for logging. Look at the documentation on the facility you are using...
—SA

1 solution

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:
C#
string[] lines = File.ReadAllLines(pathToLogFile);
But you can't say
C#
string myLine = MyStream.ReadLine(1237);
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!
 
Share this answer
 
Comments
SanSkun 6-Mar-15 23:49pm    
Hi OriginalGriff i have to read .LOG file. But i need line no. How to get it please help me out on this.
OriginalGriff 7-Mar-15 5:36am    
What generates your .LOG file?
I have seen that extension used for half a dozen different file formats!

Start by looking at the log with a text / hex editor, and see if you can work out what it contains.
SanSkun 7-Mar-15 9:57am    
My log files have only errors and warnings.So i just need to display in grid. How to read please help me out.
OriginalGriff 7-Mar-15 10:32am    
That's not the format, that's the content.

It's like the difference between a spreadsheet and the data it displays: the format is the grid of cells, the content is the strings and number it works on.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900