简体   繁体   English

IsLoggingEnabled()可以在运行时更改吗?

[英]Can IsLoggingEnabled() change at runtime?

I'm encapsulating the EntLib 5 logging application block. 我正在封装EntLib 5日志记录应用程序块。 I've seen in the documentation that every time that you want to log, you should give a look to "IsLoggingEnabled()". 我在文档中看到,每次您要记录时,都应该查看“ 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. 干杯。

You can not, through code, change the Logging settings, as said at the Enterprise Library Document . 您不能通过代码来更改“日志记录”设置,如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. 因此,这就是为什么您每次需要访问IsLoggingEnabled()操作的原因,并且缓存其值也不是一个好主意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM