.net - 检查 log4net XmlConfigurator 是否成功

标签 .net log4net

如何检查是否有调用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/

相关文章:

c# - Log4NET、ADONetAppender 和自定义字段

log4net - RollingFileAppender,滚动后,它不再追加

c# - 使用 Entity Framework 检查日期列表中的数据库表中是否存在任何值

.net - 为 .NET 编译 C 代码

c# - 如何从每个内部列表中获取所需的元素?

c# - log4net xmlconfigurator.configure需要使用dll嵌入的xml文件

c# - 如何将我的十进制线程 ID 转换为十六进制并使其以十六进制格式出现在 log4net 转换模式中?

c# - 在 C# 中嵌入 IronPython 时出现问题(缺少编译器所需的成员 'Microsoft.CSharp.RuntimeBinder.Binder.InvokeMember'

c# - 文件加载异常 : Could not load file or assembly (The assembly reference did not match the assembly definition found)

c#-4.0 - 以编程方式将 Nhibernate 设置为较低的 log4net 日志记录级别