Using EventSourceCreationData

You can use EventSourceCreationData to register an application as a source for events.

The EventSourceCreationData constructor takes the name of the Source which is your application name and a LogName which is the name of the category the EventLogEntry will be placed into, this can be Application, System, or a custom log name.

Source
The source name is often the name of the application, or the name of a component within a large application.
Log Name
Use the LogName property to identify the event log that your application writes entries to using the new source. The default value is “Application”.

The EventLog can be create on the local or remote computer by using the MachineName property.

MachineName
The name of the system on which to register the event source. The default is the local computer.

The code below checks if the EventSource exists on the remote machine and if not it creates it.

string machineName = "MyRemoteServerName";
string source = "MyCustomApp";
string logName = "Application";

if (EventLog.SourceExists(logName, machineName))
   return;

EventSourceCreationData eventSourceCreationData
   = new EventSourceCreationData(source, logName);

eventSourceCreationData.MachineName = machineName;

EventLog.CreateEventSource(eventSourceCreationData);


Comments

No comments yet.

Add Yours

  • Author Avatar

    YOU


Comment Arrow




About Author

Robert

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning hands down.