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