EventLog
This uses the Windows event log. With this control, we write events to the system log. The event log can be browsed using the Windows operating system.
EventLog
can help with debugging on your users' systems—partly because no special software needs to be installed to use the event log.
To get started with the EventLog
, open the ToolBox
window and double-click on the EventLog
item. Next, in Form1_Load
, we can write entries to the event log.
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.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("Dot Net Perls article being written.");
eventLog1.WriteEntry("Please stand by while article continues.",
EventLogEntryType.Information);
eventLog1.WriteEntry("This website is being worked on.",
EventLogEntryType.Warning,
1000);
}
}
}
The WriteEvent
method requires an EventInstance
. With an EventInstance
, you need an integer that corresponds to a string
in a separate resource file.
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 write messages to the system.