I've searched and searched and can't find the answer. We have a custom service that runs and logs into the Event Viewer. In Windows 7, there's a folder called "Applications and Services Logs". How do I log an event in there? Is it even possible?
Asked
Active
Viewed 2,520 times
2
-
This may help: http://stackoverflow.com/questions/11220837/understanding-how-trace-works-in-c-sharp – Saurabh R S Oct 02 '12 at 16:50
1 Answers
2
It will happen automatically when you create a new Event Log using something like:
EventLog.CreateEventSource("Our Source", "Our Log");
And that call requires elevated privileges, but only needs to be done once. After that, you can reference with normal privileges using.
EventLog _eventLog = new EventLog("Our Log"); // Writes to OUR event log--NOT the system created "Application"
Note: If you are moving your source from Application
to your custom log, it may need some tweaking and/or a reboot as it is not normal to move a source from one log to another.
If you are using InstalUtil, you can also create the log using a System.Diagnostics.EventLogInstaller

Jim
- 2,034
- 1
- 22
- 43
-
Thank You Jim. I created a simple console application and confirmed it worked. Can't figure out why I made it more difficult than it should be. – dave2118 Oct 03 '12 at 12:20