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

4

7

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!

Sphincter answered 1/9, 2010 at 21:50 Comment(0)
D
4

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

Dor answered 1/9, 2010 at 22:20 Comment(0)
T
5

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

Terni answered 28/4, 2011 at 13:50 Comment(1)
This was the correct answer for our problem. User account control settings were set at the default, so the developer wasn't running as Administrator. When we moved these down, everything worked fine.Holzer
C
4

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

EventLog.CreateEventSource("My Super App", "Application");
Coruscation answered 1/9, 2010 at 21:58 Comment(1)
My problem was exactly this: my custom log (source) didn't exist. Creating it using administrator privileges solved the issue. The method recommended by @Christopher Painter to create the log via script during installation is an easy solution because it doesn't involve adding security permissions the user should not have or you don't want to give.Dyann
D
4

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

Dor answered 1/9, 2010 at 22:20 Comment(0)
A
0

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

Andra answered 4/4, 2018 at 3:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.