I want to log to the Application event log from an ASP .NET app. I want to call EventLog.SourceExists to determine if an event source exists firstly and if not create it.
As documented on MSDN (http://msdn.microsoft.com/en-us/library/6s7642se.aspx): "To search for an event source in Windows Vista and later or Windows Server 2003, you must have administrative privileges. The reason for this requirement is that all event logs, including security, must be searched to determine whether the event source is unique. Starting with Windows Vista, users do not have permission to access the security log; therefore, a SecurityException is thrown."
The NetworkService user in my case will not have admin privileges, so EventLog.SourceExists throws a SecurityException as documented in MSDN.
My question is: how can I code around the call to EventLog.SourceExists defensively? Is there something I can call to firstly check if I have permission to search for event sources prior to calling EventLog.SourceExists?
Or is my only option to catch the SecurityException and take some other action inside the catch block e.g. log to an existing event source e.g. Information
Thanks
Kevin