如何检查log4net的XmlConfigurator.Configure
调用是否成功?如果日志配置无法正确加载(即文件不存在、文件格式不正确等),我想进行Web服务调用。
来自常见问题解答:
To prevent silent failure of log4net as reported as LOG4NET-342, log4net supports a way to evaluate if it was configured and also to evaluate messages generated on startup since 1.2.11. To check if log4net was started and configured properly one can check the property
log4net.Repository.ILoggerRepository.Configured
and enumerate the configuration messages as follows:
if(!log4net.LogManager.GetRepository().Configured) { // log4net not configured foreach(log4net.Util.LogLog message in log4net.LogManager.GetRepository().ConfigurationMessages.Cast<log4net.Util.LogLog>()) { // evaluate configuration message } }
LogManager.GetRepository().ResetConfiguration()
就可以完成任务! - D.R.ConfigureAndWatch
,或者“用户可以重新加载配置”是指其他内容? - Jeroen Mostert