Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 按日期戳从文件中排序内容_Vb.net_Logging - Fatal编程技术网

Vb.net 按日期戳从文件中排序内容

Vb.net 按日期戳从文件中排序内容,vb.net,logging,Vb.net,Logging,到目前为止,我已经使用Visual Studio 2015社区版程序用Visual Basic编写了一个脚本。 我正在努力寻找的是一个解决方案,我可以通过时间戳来排序内容。以下是文件内容的示例: dd.mm.yyyy hh.mm.ss text to end of line here 01.10.2015 06.50.43 Somebody tried to log into [username] with an incorrect password from [ip] 这基本上就是所有日志文

到目前为止,我已经使用Visual Studio 2015社区版程序用Visual Basic编写了一个脚本。 我正在努力寻找的是一个解决方案,我可以通过时间戳来排序内容。以下是文件内容的示例:

dd.mm.yyyy hh.mm.ss text to end of line here
01.10.2015 06.50.43 Somebody tried to log into [username] with an incorrect password from [ip]
这基本上就是所有日志文件所包含的内容。用空格隔开的日期戳和一些信息

到目前为止,我的脚本检查文件是否存在,如果文件存在,则将文件中的所有行存储到“列表(字符串)”中

当它找到所有行并到达流的末尾时,它在同一窗口的richtextbox中打印“日志”。在打印内容之前,我希望在这里发生的是,脚本按照现在存储在字符串列表中的时间戳排序,如果可能的话,从最早的字符串到最新的字符串


有什么建议吗?

一个简单但难看的解决方案可能是

lst_string.Sort(Function(x, y) DateTime.ParseExact(x.Substring(0, 19), "dd.MM.yyyy HH.mm.ss", System.Globalization.CultureInfo.InvariantCulture).CompareTo(DateTime.ParseExact(y.Substring(0, 19), "dd.MM.yyyy HH.mm.ss", System.Globalization.CultureInfo.InvariantCulture)))
但是,如果您愿意的话,最好为inputdata创建一个由datetime和comment分隔的类

Dim ld As New LoginData
ld.dateLogedIn = DateTime.ParseExact(lst_string(0).Substring(0, 19), "dd.MM.yyyy HH.mm.ss", System.Globalization.CultureInfo.InvariantCulture)
ld.commentary = lst_string(0).Substring(20)
这样,就更容易为您添加更多参数,如用户名或ip,并根据这些参数进行相应排序

lst_newList.Sort(Function(x, y) x.dateLogedIn.CompareTo(y.dateLogedIn))

我给您的第一个建议是使用正确的术语:VB.NET不同于VBScript(也不同于Basic,您也包括一个标记)。VB.NET不是脚本语言,因此,不应使用“脚本”一词。我的第二个建议是:分享你尝试过的,你的代码;不需要谈论它(也不显示它的图片),只需显示代码。但请记住,这不是一个为我编写代码的服务;你的问题必须足够具体。