EventLog Programming Architecture
Thecomponent uses these portions of the .NET Framework namespaces:
When you add an instance of the EventLog component to your application in Visual Studio, the system automatically creates the references and import statements you need to access the namespace and classes. However, if you are creating your EventLog components in code or in the Microsoft .NET Framework, you might need to create a reference toand add a statement to your project importing the same library.
For instructions on adding and removing project references, see.
Key Programming Elements in the EventLog Class
The EventLog component raises an event calledwhenever an entry is written to the log you are watching. You can define a handler for this event. In addition, you can use the following methods to interact with an instance of the EventLog component:
You can use themethod to determine whether a particular event log exists.
You can use themethod to define a string that creates a relationship between a source of events and a log, and use the method to remove this association. You can also use this method to create new custom event logs. Just type a new log name as the log in which you want to create your source, and the system will create the log automatically.
You can set theproperty to any string; it does not have to correspond to the name of your application. A single application can contain multiple components that use different source strings to identify themselves to event logs.
You can use themethod to write event information to any event log to which you have access. The WriteEntry method automatically registers your component or application as a valid source if it is not already registered with the designated log.
You can use themethod to determine whether a particular source is already registered. This is useful when you are attempting to create a new source on a given computer, because the SourceExists method will cause a run-time error if the source is already registered on that computer.
You can use themethod to retrieve a list of all the event logs on a particular computer.
You can use themethod to delete an entire event log. Use this method with caution, as deleting a log will also delete any sources registered in it.