// Create an event log object for the "Application" log EventLog eventLog = new EventLog("Application"); // Write an informational event to the log eventLog.WriteEntry("Application started.", EventLogEntryType.Information);
// Create an event log object for the "System" log EventLog eventLog = new EventLog("System"); // Write a warning event to the log eventLog.WriteEntry("Drive space is low.", EventLogEntryType.Warning);
// Create an event log object for the "Application" log EventLog eventLog = new EventLog("Application"); // Create an event source object string eventSource = "My Application"; // Create an event data object with details about the error EventLogData eventData = new EventLogData(); eventData.Add("ErrorCode", "12345"); eventData.Add("ErrorMessage", "Failed to initialize application."); // Write an error event with additional data to the log eventLog.WriteEntry(eventSource, "Application failed to start.", EventLogEntryType.Error, eventData);In summary, the System.Diagnostics EventLog WriteEntry method is used to write messages to the Windows event log. The package library for this method is System.Diagnostics.EventLog. With this method, you can write informational, warning, and error events to the log, and include additional data about the event if needed.