0

IIS 7.5 supports IIS configuration change auditing by changing setting from Event Viewer/Applications and Services Logs/Microsoft/Windows/Operational/Enable Log.

I tried it through Event Viewer and it worked great.
But what I need is not to do that manually using Event Viewer.

Instead, I need to achieve that programmatically in C# through API - an API for programming the above Event Viewer property (not IIS property) so that I can enable the logging .

Is that possible?

If so, how?

Any help is highly appreciated.

user2434400
  • 619
  • 2
  • 7
  • 13

1 Answers1

0

I was looking for the same thing ! I've just figure it out, it's quite simple:

string logName = "Microsoft-Windows-PrintService/Operational";
EventLogConfiguration log = new EventLogConfiguration(logName);

log.IsEnabled = true;

try
{
    log.SaveChanges();
}
catch (UnauthorizedAccessException e)
{
    Console.WriteLine("You need administrator privileges. " + e.Message);
}
Vic_HT
  • 411
  • 5
  • 5