TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

<< Back to C-SHARP

C# EventLog Example

Use the EventLog control from Windows Forms to access the system log.
EventLog uses the Windows event log. With this control, we write events to the system log. This can help with debugging on your users' systems—partly because no special software needs to be installed to use the event log.
Example. To get started with the EventLog, open the ToolBox window and double-click on the EventLog item. Next, in an event handler such as Form1_Load, we can write entries to the event log.Event

Note: The Source must always be set. You can set this in the Properties panel if you do not want to assign the property in code.

Property

Tip: WriteEntry can be called in a variety of ways. The overloads that have more arguments will cause more data to be stored in the event log.

Also: The extra data should be used if it will be useful in diagnosing issues through the event logs.

C# program that uses EventLog using System; using System.Diagnostics; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { eventLog1.Source = "test"; eventLog1.WriteEntry("The Dev Codes article being written."); eventLog1.WriteEntry("Please stand by while article continues.", EventLogEntryType.Information); eventLog1.WriteEntry("This website is being worked on.", EventLogEntryType.Warning, 1000); } } }
Discussion. The WriteEvent method requires an EventInstance in its signature, unlike WriteEntry. With an EventInstance, you need an integer that corresponds to a string in a separate resource file.

Tip: The event log can be located by browsing to Control Panel > System and Maintenance > Administrative Tools > View event logs.

Then: Click on Windows Logs > Application. These instructions apply to Windows Vista.

Summary. The EventLog type can be used to write entries to the system event log. After assigning the Source, you can call WriteEntry (or WriteEvent) to actually write messages to the system, which can then be found in the event log.

And: This can be beneficial to debugging software remotely—you can tell users to look through the event log.

© TheDeveloperBlog.com
The Dev Codes

Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf