I didn't reach the line that I refer to "Log".
The exception is on the line :
if (!(EventLog.SourceExists(sSource)))
Please, give me an example how running my code, in order not getting the
exception.
From the MSDN documentation on SourceExists(String):
=======
Because this method accesses the registry, you must have the appropriate
registry permissions on the local computer; otherwise, a SecurityException
will be thrown.
Note:
To search for an event source in Windows Vista, Windows XP Professional , 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. In Windows
Vista, users do not have permission to access the security log; therefore, a
SecurityException is thrown.
In Windows Vista, User Account Control (UAC) determines the privileges of a
user. If you are a member of the Built-in Administrators group, you are
assigned two run-time access tokens: a standard user access token and an
administrator access token. By default, you are in the standard user role.
To execute the code that accesses performance counters, you must first
elevate your privileges from standard user to administrator. You can do this
when you start an application by right-clicking the application icon and
indicating that you want to run as an administrator.
Note:
A service that is executing under the LocalSystem account does not have the
privileges required to execute this method. The solution is to check whether
the event source exists in the ServiceInstaller, and if it does not exist,
to create the source in the installer.
=======