EventSource.IsEnabled still returns true after keyword was removed from sink configuration.

Topics: Semantic Logging Application Block
Jan 7, 2014 at 3:58 PM
The EventSource contains the following method.
    [Event(1001,Level = EventLevel.Informational,Keywords = EventSourceTest.Keywords.BusinessLayer)]
    public void MethodEnter(string tenant, string user, string methodInfo)
    {
       if (this.IsEnabled(EventLevel.Informational, EventSourceTest.Keywords.BusinessLayer))
      {
        this.WriteEvent(1001, tenant, user, methodInfo);
      }
    }
and the following Keywords:
    public static class Keywords
    {
      public const EventKeywords BusinessLayer = (EventKeywords)1;
      public const EventKeywords ServiceLayer = (EventKeywords)2;
    }
The configuration of the out-of-process service contains only one sink with the following initial configuration:
   <consoleSink name="console-sink">
      <sources>
        <eventSource name="EventSourceTest" level="Informational" matchAnyKeyword="2"/>
      </sources>     
    </consoleSink>
Initially the the setting 'matchAnyKeyword' has the value "2". When executing 'EventSourceTest.MethodEnter', the 'IsEnabled' method returns 'false' (expected behaviour because the keywords don't match).

Now change the setting 'matchAnyKeyword' to "1". The 'IsEnabled' method returns 'true' (expected bahaviour behaviour because the keywords do match now).

Change the setting 'matchAnyKeyword' back to "2" again. The 'IsEnabled' method still returns 'true' (unexpected behaviour because the keywords don't match).

Why does 'IsEnabled' return true after the last change? It seems that the keyword '1' is not cleared for the eventsource after removing it from the sink settings. To clear it, the application, that contains the eventsource, must be restarted.
Jan 14, 2014 at 5:15 AM
I'm not seeing the same behavior as you describe. Maybe I'm doing it differently?

I configured my out of process service as described. I then started the service. Next I ran the client. IsEnabled returned true with the matchAnyKeyword set to "2".

Also note that the docs for EventSource.IsEnabled say that "The result of this method is only an approximation of whether a particular event is active". Unfortunately, I couldn't dig up anything else about what scenarios would result in the value being not 100% accurate. Your scenario might be slightly different than mine. I checked the Enterprise Library source code and it doesn't directly deal with IsEnabled so perhaps you are hitting some "issues" in the event tracing for windows infrastructure?

Maybe it you provided more details (e.g. sample project and all the steps) I could recreate the issue?

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Jan 14, 2014 at 1:40 PM
Edited Jan 30, 2014 at 9:07 AM
Here’s a link to a sample project, that I created, with the steps to reproduce the issue in the Main method: http://we.tl/Xcv70IMsuX

I’ve read the documentation on ‘IsEnabled’ too, but I still would expect the return value to be accurate in this scenario. The only thing I do is change the keyword in the sink configuration from ‘ServiceLayer’ to ‘BusinessLayer’ and back again to ‘ServiceLayer’. The EventSource doesn’t seem to pick-up the last change.

The issue also occurs when changing the level setting of the sink configuration. Sample code for this has also been added and commented out. When changing sink settings from ‘Error’ to ‘Informational’ and back to ‘Error’ again also here the EventSource doesn't seem to pick-up the last change. When using the ‘Informational’ level in our application we do a lot more of computing, than when using the Error level.

Thanks for helping.