Click here to Skip to main content
15,896,528 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys
I’m trying to write a simple event log but I'm confronted with “System.Security.SecurityException: The source was not found...”

I searched a lot but couldn’t find an efficient solution, I really really appreciate if someone help me with that 🙏🏽

I know that the source needed to be created and the key must be registered but what is the key and How should I do that?

What I have tried:

C#
String source ="DemoTestApplication";
String log = "DemoEventLog";
EventLog demolog=new EventLog(log);
demolog.Source=source;
demolog.writeEntry("This is the first message to the log", EventLogEntryType.Information);
Posted
Updated 9-Aug-18 3:07am
v2

 
Share this answer
 
From the EventLog Class documentation:
Quote:
Create the new event source during the installation of your application. This allows time for the operating system to refresh its list of registered event sources and their configuration. If the operating system hasn't refreshed its list of event sources, and you try to write an event with the new source, the write operation will fail. You can configure a new source by using an EventLogInstaller[^] object or the CreateEventSource[^] method. You must have administrative credentials on the computer to create a new event source.

An event source is a kind of identifier. This identifies your application as a source of events being written to the event logs.

An event source is usually created at install-time, in your apps installer, not at the run-time of your app. You can use the above classes to create this or you can just poke the registry keys and values in directly. See Event Sources | Microsoft Docs[^].
 
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