Enable disable loggigng Category

Topics: Logging Application Block
Apr 1, 2011 at 11:04 AM

Hi,

I have defined two categories  as follows

1) DebugCategory

2) TraceCategory

In the Category Filter i set FilterMode= AllowAllExceptDenied and Category name "TraceCategory"

I am using the "DebugCategory" category in 3 methods. has follows

Method1()

{

           obj.Logger("My first Loggign", "DebugCategory", 70001, "Unit Testing");
           
            using (traceManager.StartTrace("TraceCategory"))
            { 

Method2()

}

}

Method2()

{

           obj.Logger("My 2ndLoggign", "DebugCategory", 70001, "Unit Testing");
           
            using (traceManager.StartTrace("TraceCategory"))
            { 

Method3()

}

}

Method3()

{

           obj.Logger("My 3rd Loggign", "DebugCategory", 70001, "Unit Testing");
           
            using (traceManager.StartTrace("TraceCategory"))
            { 

}

}

 

with above setting i except the 3 messages in the 3 methods to be logged.But only the message in the first method is logged.

 

What am i doing wrong.

 

Thanks,

 

Apr 2, 2011 at 8:04 AM

can you please reply ASAP.

Apr 4, 2011 at 2:49 AM

This is because when a LogEntry is created within a trace operation, that log entry gets associated to the category specified in the trace operation.  Thus, in your call to obj.Logger in Method2 and Method3, those log entries eventually got 2 categories (DebugCategory and TraceCategory).  And since you have defined a Category Filter which disables logging for the TraceCategory operation, the LogEntry was marked as something that shouldn't be logged.  This might arguably an unexpected behavior, since the log entry is still associated to the File category which isn't disabled but that is currently how the CategoryFilter works.  You can see it in the CategoryFilter.ShouldLog method.

 

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

Apr 4, 2011 at 3:13 PM

Hi.

CategoryFilter.ShouldLog method it says true and the category name DebugCategory.That means it should log. But it fails to do so.

What is the turnaround or an alternative solution.Please reply ASAP.

 

Thanks

Apr 5, 2011 at 1:27 AM

It will return false because the LogEntry, being created inside a trace operation, contains 2 categories: DebugCategory and TraceCategory.  The easiest workaround I could think of right now is to create a custom category filter which will return true as long as one of the LogEntry's categories corresponds to a category which isn't configured to not be logged.  You would need to remove though those categories from the LogEntry which are not supposed to be logged.  For example in your case, the TraceCategory should be removed so that the LogEntry.Categories property only contains DebugCategory.

There maybe other way around this, I'll let you know if I could think of another workaround.

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