Talk about. NET's debug and trace

Source: Internet
Author: User
Tags add filter functions net switches
These two functions are mainly used to debug and track the program, and some related results can be output to the specified place. In. NET's debug mode, Debug and trace are output, and in release mode, only trace is opened by default, and you can turn trace off by setting.

The main thing is two classes of trace and debug Write,fail and assert for output, Trace also has tracewarning and traceerror two options, mainly used to output warnings and error types of messages. Can be reflected in the Event Viewer's message type. The default output is the output window for debugging, which can change the position of the output by clear the listener collection of the two classes and add a new listener ... NET provides TextWriter input to streams or files by default, EventLog Event Viewer, XML, and of course you can customize it yourself.

After performing the write operation, remember to call Debug or trace flush or close otherwise write the file message will not write the specified file, of course, you can easily set their autoflush to ensure that the contents of each write is written to the file.

Listener also has its own filter can do message filtering, you can implement the Absctract class TraceListener to create a filter class, and then assign the corresponding properties listener.

Trace can use the configuration file to control the output of the message level and output messages, originally thought that there would be any ingenious place, also feel very practical, and finally make a half-day, In fact, you still need to be in the program to BooleanSwitch or TraceSwitch for the corresponding if judgment to determine the output message. Only instances of these two classes can be configured in the configuration file by their displayname to determine whether the program outputs messages or what level of messages to output. You can also empty listener and add new listener through a configuration file.

Refer to MSDN in detail:

Tracing and debugging Settings Schema

How to: Create and Initialize Trace switches

How to: Configure Trace Switches

Description of classes for BooleanSwitch and TraceSwitch

I actually think that Debug and trace functions are still useful, probably see that is the case, mainly in a book to see that the configuration file can configure the trace message output level, etc. feel very useful functions, but the book is only the effect, but did not talk about specific applications, so today only to study the , it turns out that you still have to write if in the program, but that's just the way it is, but these features are actually useful.



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.