Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to create a event log in event viewer dynamically by coding i code like this:

C#
if (!EventLog.SourceExists("MySource"))
{
EventLog.CreateEventSource("MySource","MyNewLog"); 
}
// Create an EventLog instance and assign its source.
EventLog eventLog = new EventLog();

// Setting the source
eventLog.Source = "MySource";

// Write an entry to the event log.
eventLog.WriteEntry("An error has been generated by the application", EventLogEntryType.Error, 1002);
Posted
Updated 2-Dec-15 18:52pm
v2

1 solution

This is generally caused by having insufficient privileges to read the registry key at HKLM\SYSTEM\CurrentControlSet\services\eventlo, in this case, the Security key (/log).

Check out http://stackoverflow.com/questions/286060/what-do-i-need-to-change-to-allow-my-iis7-asp-net-3-5-application-to-create-an-e/7848414#7848414[^] for some more detail.

But in short, you’ll need some form of administrator access to create the log source, but once created, a non-administrator can then use it.


-DB
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900