简体   繁体   中英

Checking for windows events in c#, can't find this 2003 event

I read somewhere (and it is true), that windows logs eventID 2003 when you plug in a USB key, and 2102 when you unplug it. (These events do occur on my machine)

this won't work, I can't figure out why, and where to look (another log?)

using System.Diagnostics.Eventing.Reader;
class Program
{
    static void Main(string[] args)
    {
        string query = "*[System/EventID=2003]";
        EventLogQuery eventsQuery = new EventLogQuery("System", PathType.LogName, query);
        try
        {            
            EventLogReader logReader = new EventLogReader(eventsQuery);
            for (EventRecord eventdetail = logReader.ReadEvent(); eventdetail != null; eventdetail = logReader.ReadEvent())
            {
                Console.WriteLine(eventdetail.FormatDescription()); // explore the event
            }
        }
        catch (EventLogNotFoundException e)
        {
            Console.WriteLine("Error while reading the event logs");
            return;
        }
        Console.WriteLine("Done");
        Console.ReadLine();
    }
}

I can't seem to find any event. using

string query = "*[System/Provider/@Name=\"Microsoft-Windows-DriverFrameworks-UserMode\"]";

I do hav some events, thow not the 2003 I am after

I finally found a solution: as suspected, the logname was not the right one. changing "System" to "Microsoft-Windows-DriverFrameworks-UserMode/Operational" solved the problem. The microsoft documentation is once again, a total mess, and ridiculously unclear.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM