【问题标题】:read the windows event log by particular Source按特定源读取 Windows 事件日志
【发布时间】:2010-04-26 12:39:36
【问题描述】:

如何按特定来源、日期时间和类别读取 Windows 事件日志??

【问题讨论】:

    标签: c# .net event-log


    【解决方案1】:

    考虑使用EventLog Class

    EventLog 让您可以访问或自定义 Windows 事件日志,其中记录 重要软件信息 或硬件事件。使用事件日志, 您可以从现有日志中读取,写入 日志条目,创建或删除 事件源、删除日志和 响应日志条目。你也可以 创建事件时创建新日志 来源。

    【讨论】:

      【解决方案2】:

      您可以使用名为“Log Parser”的其他软件

      附带一个您可以使用的 API,安装后查看帮助文件 :)

      【讨论】:

      • 使用日志解析器的示例代码将使您的答案非常有帮助。即使我宁愿使用内部 System.Diagnostics 来阅读日志 - 其他人可能会发现这很有用。如果你更新我会 +1
      【解决方案3】:

      我知道这个问题已经很老了,但是我今天花了很多时间来构建一个解决方案,所以我想我会分享:

              Dim myEventLogEntryCollection As EventLogEntryCollection = New EventLog("Application", System.Environment.MachineName).Entries
      
              Dim myEventLogEntryArray(myEventLogEntryCollection.Count - 1) As EventLogEntry
      
              myEventLogEntryCollection.CopyTo(myEventLogEntryArray, 0)
      
              Dim QueryLog As System.Linq.IQueryable(Of EventLogEntry) = myEventLogEntryArray.AsQueryable
      
              QueryLog = QueryLog.Where(Function(i As EventLogEntry) i.Source = "MyParticularSourceName")
      
              For Each Entry As EventLogEntry In QueryLog
      
                  '... your code goes here
      
              Next
      
              myEventLogEntryCollection = Nothing
              myEventLogEntryArray = Nothing
      

      希望对他人有所帮助!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-07-04
        • 1970-01-01
        • 2012-11-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-04
        • 1970-01-01
        相关资源
        最近更新 更多