Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.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
C# 搜索特定事件ID';已存档的Windows事件日志中的_C#_Windows_Parsing_Event Log - Fatal编程技术网

C# 搜索特定事件ID';已存档的Windows事件日志中的

C# 搜索特定事件ID';已存档的Windows事件日志中的,c#,windows,parsing,event-log,C#,Windows,Parsing,Event Log,情况:我在一台服务器上有许多旧的安全事件日志(大约18GB)。日志作为evt文件保存在专用HDD分区上(->日志不包括在eventviewer中) 想要:我想在每个日志中搜索特定的事件ID 问题:我无法打开事件日志文件,该文件未包含在EventLog类的事件查看器中 想法:我使用.NET的事件日志=新事件日志() 但是我不能引用特定的事件日志文件,它位于另一个硬盘分区上。 在我看来,我尝试了所有可能的方式,比如: EventLog log = new EventLog(filepath, Co

情况:我在一台服务器上有许多旧的安全事件日志(大约18GB)。日志作为evt文件保存在专用HDD分区上(->日志不包括在eventviewer中)

想要:我想在每个日志中搜索特定的事件ID

问题:我无法打开事件日志文件,该文件未包含在EventLog类的事件查看器中

想法:我使用.NET的<代码>事件日志=新事件日志()
但是我不能引用特定的事件日志文件,它位于另一个硬盘分区上。

在我看来,我尝试了所有可能的方式,比如:

EventLog log = new EventLog(filepath, Computername)
EventLog log = new EventLog(filepath, ".")
EventLog log = new EventLog(filename, Computername, filepath)
EventLog log = new EventLog(filename, ".", filepath)
在前两个阶段,错误消息说,不允许使用像“\”这样的特殊字符。在最后两个事件中,有一条错误消息说,在计算机上找不到这样的文件“filename”(我认为他在事件日志中搜索,这些日志“包括”在事件查看器中)

问题:我想打开这样的文件-它是否与我的想法所在的类一起工作并不重要。我只想搜索一个事件ID,如果找到特定ID,则将整个事件导出为txt、csv或其他格式


提前谢谢

这里是一个将事件文件和ID作为参数的方法,它返回

用法示例:

static void Main(string[] args)
{
  var rec = GetEventRecord(@"w:\kanta\eventi.evtx", 903);
  /// due to a bug you have to set current culture to en-US or FormatDescription won't work
  /// https://connect.microsoft.com/VisualStudio/feedback/details/498054/net-3-5-sp1-eventrecord-formatdescription#
  Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
  Console.Write(rec.FormatDescription());
  Console.ReadKey();
}
static void Main(string[] args)
{
  var rec = GetEventRecord(@"w:\kanta\eventi.evtx", 903);
  /// due to a bug you have to set current culture to en-US or FormatDescription won't work
  /// https://connect.microsoft.com/VisualStudio/feedback/details/498054/net-3-5-sp1-eventrecord-formatdescription#
  Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
  Console.Write(rec.FormatDescription());
  Console.ReadKey();
}