C #: Try EventLog

Source: Internet
Author: User

1. Create a log for the source

The source is created, and the log is displayed in Event Viewer/applications and services logs/custom source, which has a relatively high level of treatment and is specially displayed.


The Administrator is required to create the source. Otherwise, crash is required.

If you have already enabled computer management, close it and then open it to see the source you just created.
CodeAs follows:

 
//Create the source, if it does not already exist.If(!EventLog. sourceexists (logsource) {EventLog. createeventsource (logsource, LOGNAME);} EventLog. writeentry (tbsourcename. text, tbmessage. text, type, getvalue (tbeventid. text), getcategory value (tbcategory. text ));

After the source is created, you do not need the Administrator identity to write logs.

In actual use, create the source when installing the software.

2. If you do not create a source, the code will be

EventLog. writeentry (tbsourcename. Text, tbmessage. Text, type, getvalue (tbeventid. Text), getcategvalue (tbcategory. Text ));

The administrator ID is required for each operation.

Logs are displayed in event viewers/Windows logs/application.

 

3. Each log contains two types of information: general and details, which are detailed but seem useless.

 

In short, it is not very nice.

Writing is also messy. Sorry!

Demo

 

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.