C # Study Notes ---- Detection

Source: Internet
Author: User

System. Diagnostics

 

Code Protocol

. Net 4 classes in the system. Diagnostics. Contracts namespace can be used for static checking code and checking code during runtime. These classes can be used by all. NET languages.

This function can be used to define the prerequisites, backend conditions, and constants in the method.

 

The parameters passed to the method for the prerequisite check. The requires () and rquires <texception> () methods can be defined using the contract class.

The post condition defines the guarantee for sharing data and returning values after the method is executed. The ensure () and ensuresonthrow <texception> () methods are post-conditions.

Constants define the protocol for the variables in the method life cycle. The contract. Invariant () method defines the conditions that must be met throughout the life cycle of the method.

 

Protocol contractclass features of interfaces

 

Tracking

The tracesource class can write trace messages. Trace the trace flag to be set by the compiler

 

The tracking configuration is completed in the <system. Diagnostics> element.

The trail is defined in <switches>.

Listener <listeners>

The listener should be used by multiple tracing sources <sharedlisteners>

 

Each listener has a filter attribute that defines whether the listener should write trace messages.

 

Event Log

EventLog read/write Event Logs

 

Use the createeventsource () method of the EventLog or eventloginstaller class. Create event Source

The log file is located in the <Windows> \ system32 \ winevt \ logs directory

To write event log entries, you can use the writeentry () or writeevent () method of the EventLog class.

 

Resource file, extension. MC

Use the message editor mc.exe to create a binary message file. Example:

mc -s EventLogMessages.mc

 

Performance monitoring

The system. Diagnostics namespace provides the following classes for performance monitoring:
Performancecounter class can be used to monitor the count and write count
Performancecountercategory class allows you to view all existing categories and create new categories.
The performancecounterinstaller class is used to install performance counters. Its usage is similar to the eventloginstaller class discussed earlier.

C # Study Notes ---- Detection

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.