Filter Diagnostic Trace Using Configuration

I often have situations when I want to have different levels of diagnostic trace in different environments, and want to configure this in web.config or app.config. Here is an example of how to do it. This example traces to the eventlog with information, warning and error levels.

    <trace autoflush="true" indentsize="0">
        <add initializeData="MyEventSource" type="System.Diagnostics.EventLogTraceListener" name="MyEventListener">
          <filter type="System.Diagnostics.EventTypeFilter" initializeData="Information" />

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.