gpt4 book ai didi

.net - 检查 log4net XmlConfigurator 是否成功

转载 作者:行者123 更新时间:2023-12-01 07:55:34 27 4
gpt4 key购买 nike

如何检查是否有调用log4net的XmlConfigurator.Configure成功了吗?如果无法正确加载日志记录配置(即文件不存在、文件格式不正确等),我想进行 Web 服务调用

最佳答案

来自 the FAQ :

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
}
}

关于.net - 检查 log4net XmlConfigurator 是否成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28723920/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com