Easy TraceLogging In C#
The .NET Framework includes some convenient ways for tracing and debugging. In this post, I'll discuss how to easily add tracing functionality to your apps to output data to a text file. First, define a trace switch in your App.config file. This should be placed in the system.diagnostics node, and the point of the switch is to specify the level at which to output data with the switch. Here's an example: <system.diagnostics> <!-- TRACE SWITCH VALUES 0 = Off 1 = Error 2 = Warning 3 = Info 4 = Verbose --> <switches> <add name="MainTraceSwitch" value="4"/> </switches> </system.diagnostics> There are five possible values: 0 = Off 1 = Error 2 = Warning 3 = Info 4 = Verbose So, if you set the value of your switch to 1, you're telling it that you only want to trace on errors. If you set it to 4, you're telling it to ...