Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
How to: Write to the Application Event Log

How to: Write to the Application Event Log (Visual C#)

Visual Studio 2008

This example writes a string to the application event log on the local computer.

System.Diagnostics.EventLog appLog = 
    new System.Diagnostics.EventLog() ;
appLog.Source = "This Application's Name";
appLog.WriteEntry("An entry to the Application event log.");

Copy the code and paste it into the Main method of a console application.

A named source can be associated with only one event log (ArgumentException). The exception is thrown when the WriteEntry method is called.

A SecurityException class can be thrown in partial trust situations.

Community Additions

© 2015 Microsoft