C # Get operating system log information

Source: Internet
Author: User
Tags local time system log

Using C # Programming, view the system log, introduce two log classes: EventLog and EventLogEntry classes, and interact with the system log.

. NET Framework class library provides the EventLog class and the EventLogEntry class to interact with the system log. They belong to the System.Diagnostics namespace.

First declare a variable: Private Eventlogentrycollection eventcollection represents a collection of system logs.

The main properties of the EventLog class are:

Entris returns a Eventlogentrycollection value that represents the contents of the event log.

Log Gets or returns the name of the journal, where the application log is application, the system log is systems, and the security log is secure, and the default value is an empty string.

Logdisplayname gets the friendly name of the event log

MachineName Gets or sets the name of the computer on which the event is read or written

Source Gets or sets the names of the sources to register and use when writing to the event log

The Evententrycollection class defines the size and enumerator of the EventLogEntry instance collection.

Some of the main properties of the EventLogEntry class are as follows:

Category gets the text corresponding to the categorynumber of the item

Categorynumber Gets the category number of the item

Data gets the binary that corresponds to the item

EntryType Gets the event type for the item, whose value belongs to the EventLogEntryType enumeration, whose main members are as follows:

Error Error event, which indicates a serious problem that the user should know about, such as function or data loss

Failureaudit Failure Audit event. It indicates a security event that occurs when an audit access attempt fails, such as when an attempt to open a file fails

Information information events. It indicates important, successful events

Successaudit successful audit event. It indicates that auditing access attempts to succeed, such as security events that occur at successful logon

Warning Warning event. It indicates a problem that is not immediately important, but this problem may indicate a condition that will cause problems in the future.

EventID the application-specific event identifier for this event entry

Index gets the entry of the item in the event log

MachineName gets the name of the computer on which the item was generated

Message gets localized messages with this event

Replacementstrings get the replacement string for the item

Source gets the name of the application that generated the event

TimeGenerated gets the local time that generated the event

TimeWritten gets the local time when the log is written to the event

UserName gets the name of the user responsible for the event

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.