You can make use of a SourceSwitch which allows you to trace different levels of messages. First start by adding some settings to app.config
<system.diagnostics>
<sources>
<source name="TraceTest" switchName="SourceSwitch"
switchType="System.Diagnostics.SourceSwitch">
<listeners>
<!-- choose one or use multiple TraceListeners -->
<add name="console" type="System.Diagnostics.ConsoleTraceListener"
initializeData="false"/>
<add name="file" type="System.Diagnostics.TextWriterTraceListener"
initializeData="error.log"/>
<remove name ="Default"/>
</listeners>
</source>
</sources>
<switches>
<!-- MSDN: 4 verbose Information, Information 3, Warning 2, Error 1, -->
<add name="SourceSwitch" value="Error"/>
</switches>
<trace autoflush="true" indentsize="4"/>
</system.diagnostics>
Within your application you can trace messages by using a TraceSource object referring to the definied name within app.config
TraceSource ts = new TraceSource("TraceTest");
ts.TraceEvent(TraceEventType.Information, 123, "event info");
ts.TraceEvent(TraceEventType.Error, 123, "event error");
ts.TraceEvent(TraceEventType.Warning, 123, "event warning");
ts.TraceInformation("any text");
ts.Flush();
ts.Close();
For some common information have a look at How to: Use TraceSource ... at MSDN. Using Dr. Google I found an related question at SO referring to a very good blogpost concerning this matter.
One thing I'd like to point out ...
To change the level at which a listener writes a trace message
The configuration file initializes the settings for the trace source
at the time the application is initialized. To change those settings
you must change the configuration file and restart the application or
programmatically refresh the application using the TraceRefresh
method. The application can dynamically change the properties set by
the configuration file to override any settings specified by the user.
For example, you might want to assure that critical messages are
always sent to a text file, regardless of the current configuration
settings.