Can I get log4net to add the real class name and not the generated closure class name?

I have a class that registers from an anonymous method. I lowered it to emphasize ...

public class SocketFlusher { private static readonly ILog Log = LogManager.GetLogger(typeof(SocketFlusher)); public void Flush() { Wait.For(timeout, () => { ... // work Log.DebugFormat("{0} bytes available", socket.Available); } } } 

My log4net configuration is good (I checked the output of log4net debug="true" and the application works). My appender layout

  <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date [%-4thread] %-5level %class{1} - %message%newline"/> </layout> 

But my log conclusion has this crazy auto-generated static class.

 2011-03-21 18:10:20,053 [5 ] DEBUG SocketFlusher+<>c__DisplayClass1 - 82 bytes available 

I want him to tell SocketFlusher what is the correct appender layout for getting this format?

+6
source share
1 answer

You want the class name to appear in the output of appender. And you follow the log4net logic of naming your registrar with a class name ...

 private static readonly ILog Log = LogManager.GetLogger(typeof($CLASSNAME$)); 

What you want to do in the application template layout is to include the %logger template template instead of the %class template.

 <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date [%-4thread] %-5level %logger{1} - %message%newline"/> </layout> 
+8
source

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


All Articles