How to read last “n” lines of log file

前端 未结 7 1229
轮回少年
轮回少年 2020-12-03 14:24

need a snippet of code which would read out last \"n lines\" of a log file. I came up with the following code from the net.I am kinda new to C sharp. Since the log file migh

7条回答
  •  心在旅途
    2020-12-03 14:44

    This is in no way optimal but for quick and dirty checks with small log files I've been using something like this:

    List mostRecentLines = File.ReadLines(filePath)
        // .Where(....)
        // .Distinct()
        .Reverse()
        .Take(10)
        .ToList()
    

提交回复
热议问题