How is the default category determined

Topics: Logging Application Block
Feb 11, 2011 at 7:18 AM

Hi,

I have a problem to understand the determination of the default category. Wich category is used when I use the followin code and configuration:

Logging code:

            var logEntry = new LogEntry();
            logEntry.Severity = severity;
            logEntry.Message = message;
            Logger.Write(logEntry);

Logging configuration

        <categorySources>
            <add switchValue="All" name="General">
                <listeners>
                    <add name="CommonRollingFileListener" />
                </listeners>
            </add>
        </categorySources>
        <specialSources>
            <allEvents switchValue="All" name="All Events" />
            <notProcessed switchValue="All" name="Unprocessed Category" />
            <errors switchValue="All" name="Logging Errors &amp; Warnings">
                <listeners>
                    <add name="Failures Listener" />
                </listeners>
            </errors>
        </specialSources>

Feb 11, 2011 at 7:24 AM

The default category can be set in the Default Logging Category property which is at the Logging Settings level.  In the xml editor, it looks like this:

<loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Feb 11, 2011 at 11:28 AM

Hi Sarah,

thank you for the answer. And what happens if I do not specify a default category in the configuration? I commented out the "categories" section. A log exception occured saying that a category "General" was not defined.

Is "General" an implicit default value for logs without an explicit category?

TIA, Matthias

Feb 14, 2011 at 1:25 AM
Edited Feb 14, 2011 at 2:53 AM

Hi,

Looking back at your code:

You didn't specify explicitly what category to use so Enterprise Library will look for the default category set at your config:

<loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">

If you specify a non existing category on your defaultCategory (like in your case, "General" is already commented out), it is expected that Enterprise Library will log an exception message: There is no explicit mapping for the categories 'General'. The implicit default value for logs will be always the name of category you set on your defaultCategory.