Article ID: 918122 - Last Review: December 3, 2007 - Revision: 1.4 BUG: You receive a security exception error message when you call the EventLog.WriteEntry method by using the EventLogPermissionAccess.Write access level in the .NET Framework 2.0On This PageSYMPTOMSConsider the following scenario. In the Microsoft .NET
Framework 2.0, you create an instance of the EventLogPermission class that has the EventLogPermissionAccess.Write access level. You call the EventLogPermission.PermitOnly method to restrict code access. Then you call
the EventLog.WriteEntry method to write an entry to the event log. In this scenario, you receive a security
exception error message that resembles the following: Unhandled Exception: System.Security.SecurityException: Request
for the permission of type 'System.Diagnostics.EventLogPermission, ...'
failed. WORKAROUNDTo work around this issue, you must request the EventLogPermissionAccess.Administer access level before you call the EventLogPermission.PermitOnly method. After you specify this access level, you can call the EventLog.WriteEntry method and write an entry to the event log. The following code example demonstrates how to write an entry to the event log
by using this workaround. Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are
listed in the "Applies to" section. MORE INFORMATIONSteps to reproduce the issue
REFERENCESFor more information about the CodeAccessPermission.PermitOnly method, visit the following Microsoft Developer Network (MSDN)
Web site: http://msdn2.microsoft.com/en-us/library/system.security.codeaccesspermission.permitonly(VS.80).aspx
(http://msdn2.microsoft.com/en-us/library/system.security.codeaccesspermission.permitonly(VS.80).aspx)
For more information about the EventLog.WriteEntry method, visit the following MSDN
Web site: http://msdn2.microsoft.com/en-us/library/6hse04t8(vs.80).aspx
(http://msdn2.microsoft.com/en-us/library/6hse04t8(vs.80).aspx)
| Article Translations
|
Back to the top
