Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Event Logging in C# on Windows 7/ 2008 Server

i am trying to make an event logger for my cmd line application. However I get this error when it tries to create the log for the first time.

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

So I found this is a because of windows 7 and some new security. So right now I have to give the .exe admin rights.

Is there a way around this so it would not need admin rights? I don't know if people would feel too good if they have to contently run my application with admin rights.

I am planning to put this later on a windows 2008 machine so I am guessing it will suffer from the same problem.

like image 221
chobo2 Avatar asked Jul 15 '10 22:07

chobo2


People also ask

What is meant by event log?

Event logging provides a standard, centralized way for applications (and the operating system) to record important software and hardware events. The event logging service records events from various sources and stores them in a single collection called an event log.

What are event logs and its example?

An event log is a basic "log book" that is analyzed and monitored for higher level "network intelligence." It can capture many different types of information. For example, it can capture all logon sessions to a network, along with account lockouts, failed password attempts, etc.

What is event source logging?

The event source is the name of the software that logs the event. It is often the name of the application or the name of a subcomponent of the application if the application is large. You can add a maximum of 16,384 event sources to the registry. The Security log is for system use only.

How do you write an event log?

The Write-EventLog cmdlet writes an event to an event log. To write an event to an event log, the event log must exist on the computer and the source must be registered for the event log. The cmdlets that contain the EventLog noun (the EventLog cmdlets) work only on classic event logs.


1 Answers

You could create the event source at the point of installation so they only need to make that choice once. Once the source is created in the registry you can add events to it without the need for admin rights.

As well as the CreateEventSource function there is also the EventLogInstaller class:

http://msdn.microsoft.com/en-us/library/system.diagnostics.eventloginstaller.aspx

WiX also offers this functionality in it's Utility extension:

How do you create an event log source using WiX

like image 188
fletcher Avatar answered Sep 24 '22 18:09

fletcher