What code must you use?

You have been asked to profile a business application that can be accessible using the Event Log API.
You have started by adding the following code to create a custom event log:
if (EventLog.SourceExists (“Application1”))
EventLog.DeleteEventSource (“Application1”);
//Create new event log
EventLog.CreateEventSource (“Application1”, “Profile”);
You need to write an event to the Application1 event log.
What code must you use?

You have been asked to profile a business application that can be accessible using the Event Log API.
You have started by adding the following code to create a custom event log:
if (EventLog.SourceExists (“Application1”))
EventLog.DeleteEventSource (“Application1”);
//Create new event log
EventLog.CreateEventSource (“Application1”, “Profile”);
You need to write an event to the Application1 event log.
What code must you use?

A.
EventLog log = new EventLog ();
log.Source = “Application1”;
log.Log = “Profile”;
log.WriteEvent(“Writing to event log.”);

B.
EventLog log = new EventLog ();
log.Source = “Profile”;
log.Log = “Application1”;
log.WriteEvent(“Writing to event log.”);

C.
EventLog log = new EventLog ();
log.Source = “Application1”;
log.Log = “Profile”;
log.WriteEntry(“Writing to event log.”);

D.
EventLog log = new EventLog ();
log.Source = “Profile”;
log.Log = “Application1”;
log.WriteEntry(“Writing to event log.”);

Explanation:
This code instantiates an EventLog object, sets the Source and Log properties, and invokes the WriteEntry method
to output the message to the event log.
The EventLog object allows you to create, delete, read from, or write to Windows event logs.
In this scenario, you use the CreateEventSource method to create a custom event log. When calling the CreateEventSource method, you pass the method two arguments. The first argument represents the source name for the event log, and the second represents the name of the event log.
Next, you want to write an entry to the Application1 event log. To write to an event log, you must first identify the event source and the name of the event log to which you want to write.
The Source property specifies the event source, and the Log property specifies the name of the event log.
There are two methods to writ to the EventLog object:
WriteEntry and WriteEvent.
The WriteEntry method is an overloaded method used to write a text message to an event log.
The WriteEvent method is used to write localized resources and event instances to an event log.
Incorrect Answers:
A, B: The WriteEvent method is used to write localized resources and event instances to an event log.
D: You should not use the code fragments that specify a value of “Profile” for the Source property and
a value “Application1” for the Log property because they would attempt to write the entry to an event log named Application1.



Leave a Reply 0

Your email address will not be published. Required fields are marked *