本文介绍了使用C#解析日志文件 - (日志文件已经格式化并且格式为.xlsx。它包含许可证使用数据,目标是计算总使用量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好, 我正在解决这个问题,我有点想到这些零件,但我无法把它们放在一起。首先,我有一个xlsx格式的处理日志文件数据,结构如下: STATUS LICENSE USERNAME HOSTNAME DATE TIME OUT Complte_Package user8 ABCD1458108 1-Jan 6:30:36 OUT Custom_Package_1 user5 XYZQ152102 1-JAN 7:00:35 OUT Complte_Package user6 LMOD1458561 1-Jan 7:12:25 OUT Complte_Package user1 KROL253584 1-Jan 7:23:15 OUT Custom_Package_2 User7 BCDL255657 1-Jan 8:56:12 IN Custom_Package_2 User7 FGKL1255657 1月1日 9:46:38 给定数据来自连续日志文件,因此当从服务器签出许可证时,它会将状态标记为OUT并记录许可证类型,用户名,主机名,日期和时间以及返回时,它会记录状态为IN的相同信息 - OUT时间和IN时间之间的差异是总使用量。 我确实知道我可以使用microsoft.office.interop.excel并读取此文件,但我不知道如何将整个文件读入字典中然后计算用法。你们可以建议如何将其读入字典吗?一旦将其加载到字典中并将给定列作为键,我想计算使用情况作为许可证包/用户/月。我有35000个条目,日志文件不断增长。任何帮助/提示将不胜感激 (PS:c#非常新)解决方案 你确定吗?它实际上是一个带有csv扩展名的文本类型文件,而不是你可以轻松读入Excel吗? 如果你对c#很新,为什么不满足于比Interop& amp;'更简单'的方法Excel? a)使用File.ReadAllLines将(文本)文件读入字符串数组(或者,如果它变得太大,请逐行读取 b)对于每一行(不包括标题),使用带有制表符或逗号的String.Split()(在您的示例中可以是制表符),将字符串拆分为字段 c)然后想想你的字典和密钥等Hi All,I am in a fix with this problem and I kind of have figured the parts but I am not able to bring the together. To begin with I have a processed log file data in xlsx format and the structure looks like this :STATUS LICENSE USERNAME HOSTNAME DATE TIMEOUT Complte_Package user8 ABCD1458108 1-Jan 6:30:36OUT Custom_Package_1 user5 XYZQ152102 1-Jan 7:00:35OUT Complte_Package user6 LMOD1458561 1-Jan 7:12:25OUT Complte_Package user1 KROL253584 1-Jan 7:23:15OUT Custom_Package_2 User7 BCDL255657 1-Jan 8:56:12IN Custom_Package_2 User7 FGKL1255657 1-Jan 9:46:38The given data is from a continuous log file, so when a license is checked out from the server it marks the status as "OUT" and logs the License type,username,hostname,date and time and when it is returned, it records the same info with the status as "IN" - The difference between the OUT time and IN time is the total usage.I did figure out that I could use microsoft.office.interop.excel and read this file but I am not sure how to read this whole file into a dictionary and then calculate the usage. Can you guys please suggest how to read this into a dictionary? Once its loaded into dictionary with the given columns as keys I would like to calculate the usage as license package/user/month. I have 35000 entries and the log file continuously grows. Any help/tip will be much appreciated(PS: Very new to c#) 解决方案 are you sure ? is it actually a text type file with a csv extension instead that you can read into Excel easily ?If you're very new to c#, why not settle for a 'simpler' method than Interop & Excel ?a) read the (text) file into a string array, using File.ReadAllLines(, or, if it grows too big, read it line by lineb) For each line (not including the header) use String.Split() with tab or comma (could be tab in your example), to split the string into 'fields'c) Then think about your dictionary and keys and such 这篇关于使用C#解析日志文件 - (日志文件已经格式化并且格式为.xlsx。它包含许可证使用数据,目标是计算总使用量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-23 20:58