Read Event Log Remotely with .NET

后端 未结 2 1225
猫巷女王i
猫巷女王i 2020-12-31 15:33

I want to read the Event Log on a remote computer to check for errors during testing. Here\'s some relevant code:

public bool CheckEventLogs(DateTime start)         


        
2条回答
  •  暖寄归人
    2020-12-31 16:13

    WMI is incredibly useful for this, a snippet like

    SELECT Logfile,TimeGenerated,Type,SourceName,Message FROM Win32_NTLogEvent
    

    Would allow you to query the logs. This utility from MS will allow you to explore WMI and will even build the .net code to invoke the queries.

    Another benefit to this is that its going to get all the events and bring them local to the application where you can parse them at your leisure. Iterating the events in the way you are doing now is prone to failure if the connection is broken while you are processing (incidentally this is the same method that is typically employed with database access).

提交回复
热议问题