Display log file information on a web page using ASP.NET MVC paging

I have logs stored in a txt file in the following format.

====== 8/4/2010 10:20:45 AM ================================== ==================================================

Donation Processing

====== 8/4/2010 10: 21: 42A M ================================== ==== ============

Sending information to the server

====== 8/4/2010 10:21:43 AM ================================== ========================================= ========== =

I need to parse these lines into a list in which the information between the lines "====" is counted as one record to be displayed on a web page using swap in ASP.NET MVC.

Example: the first record will be

====== 8/4/2010 10:20:45 AM ====================================================================== ===================

. ?

+3
2

, , =====

var sBuilder = new StringBuilder()
bool lineEnd = false;
var items = new List<string>();
string currentLine = String.Empty
using(var file = new StringReader("log.txt"))
{
  while( (currentLine = file.ReadLine()) != null)
  {
    if(currentLine.EndsWith("===="))
    {
        items.Add(sBuilder.ToString());
        sBuilder.Clear();
    }
    else
        sBuilder.Append(currentLine);
  }
}

,

0

... . :

string texty = "=====........"; //File data
var matches = Regex.Matches(texty, @"={6}(?<Date>.+)={41}\s*(?<Message>.+)");

var results = matches.Cast<Match>().Select(m => new {Date = m.Groups["Date"], Message = m.Groups["Message"]});

.

0

Source: https://habr.com/ru/post/1760000/


All Articles