Is there a programmatic way which allows me to enable an EventLog if it was disabled by default? In short, I just need to know if I can enable a specific EventLog so that I can use the events programmatically.
Thanks
Is there a programmatic way which allows me to enable an EventLog if it was disabled by default? In short, I just need to know if I can enable a specific EventLog so that I can use the events programmatically.
Thanks
To Enable the Windows Event Log use the wevtutil
In particular to enable the Word pad log do the following:
wevtutil sl "Microsoft-Windows-Wordpad/Admin" /e:true
Assuming you're talking about enabling/disabling system logs (Application, Security, Setup, System) I don't think it's possible.
Here's Event Log on Windows Dev center (required deeper poking to find useful info) http://msdn.microsoft.com/en-us/library/windows/desktop/aa964766%28v=vs.85%29.aspx
Here's part about registry settings: http://msdn.microsoft.com/en-us/library/windows/desktop/aa363648%28v=vs.85%29.aspx
Group Policy setting: http://blogs.technet.com/b/askds/archive/2008/08/12/event-logging-policy-settings-in-windows-server-2008-and-vista.aspx
Which interestingly allow you to enable or disable Setup log but none of the other default ones.
I just think that if you can't do it through registry or group policy then it can't be done.
Edit:
There is no way to programatically enable/disable event logs through the API. The only proof I have is that it's not there. So I checked other ways: PowerShell, WMI, Registry, Group Policy - something you can control from within the code. No joy. However, the only way to disable event log is to stop the service.
This should enable the event log programatically. It uses an EventLogSession parameter
var elSession = new EventLogSession("computername", "domain", "username", password, SessionAuthentication.Default);
var elConfig = new EventLogConfiguration("Microsoft-Windows-Wordpad/Admin", elSession);
if (!elConfig.IsEnabled)
{
elConfig.IsEnabled = true;
elConfig.SaveChanges();
}