Enterprise Library 5.0 logging application fluent configuration

Topics: Logging Application Block
Jul 18, 2013 at 9:24 AM
hi!
I am using fluent to configure the logging application block via source.
Tracelistener is a custom database tracerlistener (based on the one in a Hands On Lab I think). As a Fallback a Flat File Listener is configured.
Every thing works fine so far but one problem is left:
If a category appears that is not known i don't want the not mapped exception i want it to be added. As far as my research goes this could be archieved by
<notProcessed switchValue="off" name="Unprocessed Category" />
so 2 questions:
-- is this correct?
-- How do I achive this using fluent. I tried to find info about this quite for a while now. Or am I totally wrong with this

Not directly relevant but this is my config so far (left away the parameter setup for the custom trace listener because it's not part of the problem):
        builder.ConfigureLogging()
            .WithOptions
            .DoNotRevertImpersonation()
            .LogToCategoryNamed("General")
            .WithOptions
            .SetAsDefaultCategory()
            .SendTo
                .Custom<ExtendedFormattedDatabaseTraceListener>("Database Listener").UsingInitData(tracerParametersAsString)
                    .FormatWith(formatterBuilder)

            .SpecialSources
                .LoggingErrorsAndWarningsCategory
                    .SendTo
                        .FlatFile("Fallback Log file")
                            .FormatWith(formatterBuilder)
                            .ToFile(_fallbackFilePath)
            .SendTo.SharedListenerNamed("Database Listener");
Thanks premilary for all ideas/solutions/suggestions
Jul 18, 2013 at 4:29 PM
The SpecialSources.UnprocessedCategory (<notProcessed> in xml) let's you send unprocessed categories to a trace listener. This is not set by default. Another setting which is true by default is to warn if no categories match (logWarningsWhenNoCategoriesMatch attribute in xml). You can turn this off using the fluent interface by using DoNotLogWarningsWhenNoCategoryExists():
        builder.ConfigureLogging()
            .WithOptions
            .DoNotRevertImpersonation()
            .DoNotLogWarningsWhenNoCategoryExists()
            .LogToCategoryNamed("General")
            .WithOptions
            .SetAsDefaultCategory()
            .SendTo
                .Custom<ExtendedFormattedDatabaseTraceListener>("Database Listener").UsingInitData(tracerParametersAsString)
                    .FormatWith(formatterBuilder)

            .SpecialSources
                .LoggingErrorsAndWarningsCategory
                    .SendTo
                        .FlatFile("Fallback Log file")
                            .FormatWith(formatterBuilder)
                            .ToFile(_fallbackFilePath)
            .SendTo.SharedListenerNamed("Database Listener");
With the above configuration you should only see entries written for categories you have defined.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Marked as answer by randylevy on 10/7/2013 at 11:09 PM
Jul 19, 2013 at 8:12 AM
Thanks for your quick answer.
Works fine now.