SoFunction
Updated on 2025-03-07

C# 3.0 How to write Windows event logs using EventLog class

This article describes the method of using the EventLog class to write Windows event logs. Share it for your reference. The details are as follows:

In programs, specified information (including exception information and normal processing information) is often required to write to the log. In C# 3.0, you can use the EventLog class to transfer various messages

The message is written directly to the Windows log. The EventLog class is in the namespace. We can use Administrative Tools > Event Viewer

You can view the Windows logs we wrote

The following is an example of using the EventLog class to write logs to an application (Application). The log type is specified using the EventLogEntryType enumeration type.

EventLog log = new EventLog();
try
{
   = "My Application";
  ("Processing Information 1", );
  ("Processing Information 2", );
  throw new ("file not found");
}
catch ( exception)
{
  ("Processing Information 2", );
}

I hope this article will be helpful to everyone's C# programming.