Search code examples
c#wmievent-viewer

how to access local event log using local ip address in c#


I can access the local system event log information using "." and "Machinename". but i cannnot access the local system event log by using ip address.

the code is:

EventLog Logs = new EventLog("Application",".");//EventLog("Application","Machinename");

this also works fine. but when i am using it for ip address like

EventLog Logs = new EventLog("Application","XXX.XX.X.X");

please help me to resolve this.

Thanks in Advance..


Solution

  • Try converting the IP address to a host name using Dns.GetHostEntry:

    using System.Net;
    
    string hostName = Dns.GetHostEntry("xxx.xx.x.x").HostName.Split('.')[0];
        EventLog log = new EventLog("Application", hostName);