How do I avoid this SecurityException when writing to the Event Log?

限于喜欢 提交于 2019-12-12 08:49:02

问题


I can't seem to write to the event log in .NET. I get the following exception:

System.Security.SecurityException: The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security.

I don't want to access the Security log. How do I get around this error? Thanks!


回答1:


You can try to create an event log in your application like Lachlan suggests but realize that this will require administrator privs. Instead I reccomend that you take care of this in your installer / deployment automation layer.

I use WiX so I recommend reading:

How do you create an event log source using WiX




回答2:


You can try to Start Visual Studio with Run As Administrator permission.




回答3:


Have you set the source for your eventlog? E.g.:

EventLog.CreateEventSource("My Super App", "Application");



回答4:


If, for example, you are developing a service application that use EventLog class and need to test somes classes before running the service, which need to be installed. You can add a app.manifest to your project (not service project, maybe a console application), and in 'requestedExecutionLevel' set the level to "requireAdministrator", when you try to run your project from visual studio, it will ask to elevate the permissions that will (if want)i restart the visual studio, then will be can to use EventLog class.

hope this help,

antonio



来源:https://stackoverflow.com/questions/3622396/how-do-i-avoid-this-securityexception-when-writing-to-the-event-log

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!