Allow or Deny logs based on Category Filter

Topics: Logging Application Block
Nov 7, 2013 at 2:06 PM
Assume I have the following categories: Debug, Information, Warning, Exception

Here's want I to achieve: Allow log entries go thru to be based on these categories, IFF there is an exception. However, I still have the ability to turn on/off Debug, when no exception occurs.

Is there anywhere I can do this via configuration?
Or I need to write a custom filter?

Please advice.
Thanks.
Editor
Nov 10, 2013 at 7:50 PM
Let me just restate so we are on the same page:

You have 4 categories: Debug, Information, Warning, Exception. By default you only want the Exception category to be logged but you want the ability to enable the Debug category at runtime.

If that is the scenario then you can use the built-in category filter to do this. For example, you could deny all categories exception Exception in the XML configuration file:
        <logFilters>
            <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.CategoryFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                categoryFilterMode="DenyAllExceptAllowed" name="Category Filter">
                <categoryFilters>
                    <add name="Exception" />
                </categoryFilters>
            </add>
        </logFilters>

If you wanted to allow other categories you could add them to the categoryFilters.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to