【问题标题】:log4net class library is not outputting any loglog4net 类库没有输出任何日志
【发布时间】:2016-07-01 18:44:22
【问题描述】:

所以我在一个解决方案中有几个项目。 我知道您可以在 SAME 项目中创建一个日志助手类来执行此操作。但是,我想知道是否可以将其扩展到所有项目

我创建了一个类库,以便我的每个项目都可以根据他们的项目名称获取 log4net 记录器。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace Log4NetLogHelper
{
    public class LogHelper
    {
        public static log4net.ILog GetLogger([CallerFilePath]string filename = "")
        {
            return log4net.LogManager.GetLogger(filename);
        }
    }
}

我检查了助手类中的文件名,它是正确的。但是,没有日志输出。 (文件等中没有记录任何内容)。我 99.99% 确定这不是我的配置,因为如果我不使用辅助类,log4net 可以正常工作。

using Log4NetLogHelper;

[assembly: log4net.Config.XmlConfigurator(Watch =true)]

namespace A
{
    public class B
    {
       private static readonly log4net.ILog log = LogHelper.GetLogger();
       static void Main(string[] args)
       {
          log.Error("test");
       }
    }
}

【问题讨论】:

    标签: logging visual-studio-2015 log4net .net-4.6


    【解决方案1】:

    我想我明白了。我认为问题在于我忘记将[assembly: log4net.Config.XmlConfigurator(Watch =true)] 放在我的图书馆项目中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-02
      • 2015-03-07
      • 2021-05-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多