How to access custom event logs via WMI Win32_NTEventlogFile

G

Guest

I am trying to access the custom event logs on a Windows XP Pro system
running .NET 1.1 in C#. I am using the following to do that:

using System;
using System.Management;

namespace WMIEventLogTest
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
ManagementClass mc = new ManagementClass("Win32_NTEventlogFile");
ManagementObjectCollection moc = mc.GetInstances();
Console.WriteLine( "List event log name using ManagmentObjectCollection:");
foreach (ManagementObject mo in moc)
{
Console.WriteLine( mo["LogfileName"].ToString());
}
Console.WriteLine( "--------------");
Console.WriteLine( "List event log names using MangementObjectSearcher:");
SelectQuery query = new SelectQuery( "SELECT * FROM Win32_NTEventlogFile");
ManagementObjectSearcher searcher = new ManagementObjectSearcher( query);
foreach (ManagementObject mo in searcher.Get())
{
Console.WriteLine( mo["LogfileName"].ToString());
}
}
}
}

The output is:
List event log name using ManagmentObjectCollection:
Application
Security
System
--------------
List event log names using MangementObjectSearcher:
Application
Security
System

I have some custom event logs configured on the system but this program does
not list them. I am running the program as Administrator.

I am looking for suggestions on how to access these log files through WMI.

What do you think?

Thank you!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top