.net 完全重置NLog配置 请考虑以下代码: public static void Main(string[] args) { // 1. At this point NLog will search for most common configuration locations, // as described in http://nlog-project.org/wiki/Configuration_file. var loggerOne = LogManager.GetLogger("LoggerOne"); // 2. We set NLog configuration to null, hoping that the next time the // configuration is requested the whole process (1) will be repeated. LogManager.Configuration = null; // 3. NLog won't actually repeat process (1), and so logging is disabled for // the following logger since the configuration is still null. var loggerTwo = LogManager.GetLogger("LoggerTwo"); }
浏览NLog的源代码很明显,这与基础.net 完全重置NLog配置 请考虑以下代码: public static void Main(string[] args) { // 1. At this point NLog will search for most common configuration locations, // as described in http://nlog-project.org/wiki/Configuration_file. var loggerOne = LogManager.GetLogger("LoggerOne"); // 2. We set NLog configuration to null, hoping that the next time the // configuration is requested the whole process (1) will be repeated. LogManager.Configuration = null; // 3. NLog won't actually repeat process (1), and so logging is disabled for // the following logger since the configuration is still null. var loggerTwo = LogManager.GetLogger("LoggerTwo"); },.net,nlog,.net,Nlog,浏览NLog的源代码很明显,这与基础LogFactory的configLoaded字段有关,该字段在启动时设置为true,在将null分配给Configuration属性后,不会重置为false(对我来说,这是最有意义的). 我的问题是,我是否在这个过程中遗漏了一些东西,或者是否真的没有办法(当然,不使用反射)强制NLog从头开始重新配置自己并重复这个过程(1)首先,让我问一下您试图实现的是什么?这更像是一个尝试了解NLog如何工作的练习吗?有没有什么特别的事情是我们想要完成的?如果是后者,也许
LogFactory
的configLoaded
字段有关,该字段在启动时设置为true
,在将null
分配给Configuration
属性后,不会重置为false
(对我来说,这是最有意义的). 我的问题是,我是否在这个过程中遗漏了一些东西,或者是否真的没有办法(当然,不使用反射)强制NLog从头开始重新配置自己并重复这个过程(1)
首先,让我问一下您试图实现的是什么?这更像是一个尝试了解NLog如何工作的练习吗?有没有什么特别的事情是我们想要完成的?如果是后者,也许已经有了一种被认可的方式来做你想做的事情
话虽如此,我有一个想法(我没有尝试过)可能会奏效
在查看NLog源时,您似乎可以执行以下操作:
LogManager.Configuration = new LoggingConfiguration();
分配一个新的LoggingConfiguration看起来会导致日志配置过程从头开始。我不确定在旧配置生效时可能检索到的任何记录器会发生什么情况。它们仍然有效吗?他们会做些什么吗