Registering a method or class name always writes the Common.Logging method

I am using log4net with .NET Common.Logging . I configured the message template to include the method and class name like this:

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

The problem is that I always get the name of the Common.Logging method and class:

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

This is the most incomprehensible. Is there a way to print my method name ?

+4
source share
2 answers

I think you need to change Common.Logging. In the Log4NetLogger.cs file, replace the following line

 private readonly static Type declaringType = typeof(Log4NetLogger); 

with

 private readonly static Type declaringType = typeof(AbstractLogger); 

That should do the trick. There are some explanations here why this should work.

+3
source

This format works with my configuration

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

My registrar is defined as

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

I use these unmodified dlls

  • Common.Logging.dll ver 2.0.0.0
  • Common.Logging.Log4Net.dll ver 2.0.0.0
  • log4net.dll ver 1.2.10

Update: In registration messages, I add the method name to the registration call as text, so I don't have the overhead of parsing the call stack to get the method name.

+1
source

Source: https://habr.com/ru/post/1335409/


All Articles