0

I'm encapsulating the EntLib 5 logging application block. I've seen in the documentation that every time that you want to log, you should give a look to "IsLoggingEnabled()". The fact that it's a method and not a property, tell me that is an operation that takes some time to be done, but... could I cache that value in a local variable and check if it's possible to log or not based on it?

Cheers.

Paul R
  • 208,748
  • 37
  • 389
  • 560
vtortola
  • 34,709
  • 29
  • 161
  • 263

1 Answers1

1

You can not, through code, change the Logging settings, as said at the Enterprise Library Document. But there you can also read that:

Note:
Run time changes to the configuration of the Logging Application Block are automatically detected after a short period, and the logging stack is updated. However, you cannot modify the logging stack at run time through code. For details of using configuration mechanisms that you can update at run time, see Updating Configuration Settings at Run Time.

That is, while you can't enable/disable programatically the logging, it can change at run time if configuration edited manually.

So, that is why you'll need to access the IsLoggingEnabled() operation every time, and it's not a good idea to cache it's value.

Tomas Narros
  • 13,390
  • 2
  • 40
  • 56
  • I see. So, in a web environment is not a problem because every time you alter the web.config, iis reset the app. But in a windows app or service, you could change the values and then it would make a problem. Am I right? – vtortola Feb 09 '11 at 14:42
  • 1
    Well, so it seems: http://msdn.microsoft.com/en-us/library/ff664640%28v=PandP.50%29.aspx "In Windows Forms applications, you can restart the application to cause it to read the all of the new configuration information. Web Forms (ASP.NET) applications will detect and reload the configuration information, but the standard behavior of ASP.NET causes the application to restart when you edit the configuration file, which causes all state to be lost for the application." – Tomas Narros Feb 09 '11 at 15:19
  • You can't modify the logging stack at runtime through code but you can modify the configuration at runtime through code which causes the logging stack to be modified at runtime. :) – Randy Levy Feb 09 '11 at 19:15