Switching trace levels

The Trace.WriteLine calls are left in your code even after release. So, we need a way to control when they are output. We can do this with a trace switch.

The value of a trace switch can be set using a number or a word. For example, the number 3 can be replaced with the word Info, as shown in the following table:

Number Word Description
0 Off This will output nothing
1 Error This will output only errors
2 Warning This will output errors and warnings
3 Info This will output errors, warnings, and information
4 Verbose This will output all levels

 

Add some statements to the end of the Main method to create a trace switch, set its level using a passed command line parameter, and then output the four trace ...

Get C# 7.1 and .NET Core 2.0 – Modern Cross-Platform Development - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.