The EventLog component reads and writes event logs and the eventlog component reads and writes logs.

Source: Internet
Author: User

The EventLog component reads and writes event logs and the eventlog component reads and writes logs.

The EventLog control in. Net allows you to access or customize Windows event logs, which record information about important software or hardware events. You can use EventLog to read existing logs, write items to logs, create or delete event sources, delete logs, and respond to log items. You can also create a log when creating an event source.

 

View Code // instantiate a Windows event log instance
EventLog log1 = new EventLog ();

Private void button10_Click (object sender, EventArgs e)
{
// Whether the event source exists
If (! EventLog. SourceExists ("TestLog "))
{
// Create an event Source, create an application, and use the specified Source as the daily
// Valid event source for the log entry written in the log, and the application is on the local computer. The source name used for p1 registration,
// The Name Of The log written by the p2 source entry
EventLog. CreateEventSource ("TestLog", "log1 ");
}
// Log name
Log1.Log = "log1 ";
// Event source name
Log1.Source = "TestLog ";
// Machine name
Log1.MachineName = ".";
// Write log information, specifying the category
Log1.WriteEntry ("An error has occured", EventLogEntryType. Error );

// Traverse the existing log information
Foreach (EventLogEntry item in log1.Entries)
{
Console. WriteLine (item. Message + "\ t" + item. TimeGenerated );
}

 

After execution, you can view the recorded log information in the computer management.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.