PrepAway - Latest Free Exam Questions & Answers

Which code segment should you use?

You are developing an application by using C#. The application will write events to an event log.
You plan to deploy the application to a server.
You create an event source named AppSource and a custom log named AppLog on the server.
You need to write events to the custom log.
Which code segment should you use?

PrepAway - Latest Free Exam Questions & Answers

A.
Option A

B.
Option B

C.
Option C

D.
Option D

Explanation:
Source should be AppSource:
* New-EventLog
Creates a new event log and a new event source on a local or remote computer.
Parameters include:
-Source<String[]>
Specifies the names of the event log sources, such as application programs that write to the event log. This
parameter is required.

4 Comments on “Which code segment should you use?

  1. cristis says:

    A is the correct answer. You first need to create the log.

    public class WriteToEventLogs
    {
    public void CreateEventSource()
    {
    EventLog.CreateEventSource(“AppSource”, “MyLog”);
    }

    public void WriteToEventLog(string message, EventLogEntryType eventLogEntryType)
    {
    EventLog eventLog = new EventLog { Source = “AppSource”, EnableRaisingEvents = true };
    eventLog.WriteEntry(message, eventLogEntryType);
    }
    }
    The message won’t show in the Application log.
    Go the the root of the event viewer and you’re going to identify the log in the main window. You can create a Custom View for it.




    1



    0

Leave a Reply