4

我将log4net.NET Common.Logging 一起使用。我配置了一个消息模式以包含方法和类名,如下所示:

<layout type="log4net.Layout.PatternLayout">
  <conversionPattern value="%-5level [%M %C] - %message%newline" />
</layout>

问题是我总是得到 Common.Logging 方法和类的名称:

FATAL [Fatal Common.Logging.Factory.AbstractLogger] - log message
INFO  [Info Common.Logging.Factory.AbstractLogger] - log message
DEBUG [Debug Common.Logging.Factory.AbstractLogger] - log message

这是最没用的。有没有办法打印我的方法名称

4

2 回答 2

3

我认为您需要修改 Common.Logging。在文件 Log4NetLogger.cs 中替换以下行

private readonly static Type declaringType = typeof(Log4NetLogger);

private readonly static Type declaringType = typeof(AbstractLogger);

这应该可以解决问题。是一些解释为什么这应该起作用。

于 2011-01-13T14:33:49.050 回答
1

这种格式适用于我的配置

<layout type="log4net.Layout.PatternLayout">
  <conversionPattern value="%-5level [%logger] - %message%newline" />
</layout>

我的记录器定义为

private static readonly Common.Logging.ILog logger = 
              Common.Logging.LogManager.GetCurrentClassLogger();

我使用这些未修改的 dll

  • Common.Logging.dll 版本 2.0.0.0
  • Common.Logging.Log4Net.dll 版本 2.0.0.0
  • log4net.dll 版本 1.2.10

Update: In the logging messages i add the methodname into the logging call as text so i have no performance overhead with analysing the call stack to get the methodname.

于 2011-01-13T14:46:47.463 回答