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?
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.
Looks like it should be the answer A?
1
0
answer: A
https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.eventlog.writeentry?view=netframework-4.7.2
Check the signature of the WriteEntry method. And also the condition: “You create an event source named AppSource”
3
0
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
The custom log also appears under Applications and Services Logs
0
0