0

I followed this link to implement a wrapper class with singleton How to make Log4Net wrapper class as a singleton class?

My logger works fine, but how can I properly logging conversionPattern Logger and Method?

Thank you all

Community
  • 1
  • 1
Marco
  • 71
  • 2
  • 8
  • As you only have one logger (the singleton) you can't set the logger name. Regarding the method, as log4net internally uses a StackTrace [as per the documentation](https://logging.apache.org/log4net/log4net-1.2.13/release/sdk/log4net.Layout.PatternLayout.html), you will always see the Singleton in the trace. – stuartd Apr 11 '17 at 13:57
  • 1
    Also regarding `method`, the docs say _"Used to output the method name where the logging request was issued. **WARNING** Generating caller location information is extremely slow. Its use should be avoided unless execution speed is not an issue."_ – stuartd Apr 11 '17 at 13:59
  • .. and _"By default, Debug builds include debug symbols, while Release builds do not. The debug symbols contain most of the file, **method name**, line number, and column information used in constructing StackFrame and StackTrace objects. StackTrace might not report as many method calls as expected, due to code transformations that occur during optimization." This means that in a Release build the caller information may be incomplete or may not exist at all! Therefore caller location information cannot be relied upon in a Release build."_ – stuartd Apr 11 '17 at 14:00
  • The fact is, using a singleton (or other wrapper) makes log4net less flexible and less powerful - apart from the limitations you've found, you can't e.g. have different log levels per logger – stuartd Apr 11 '17 at 14:01
  • Ok, I didn't want to declare log in every class. But If I understand, I can't do it without making log4net less flexible and less powerful... right? – Marco Apr 11 '17 at 14:19
  • Afraid so, yes. – stuartd Apr 11 '17 at 14:23
  • We got the same issue, use the Ilogger interface instead. For further reading : http://apache-logging.6191.n7.nabble.com/ILog-Wrapping-tc23132.html#none http://stackoverflow.com/questions/157232/how-to-log-methodname-when-wrapping-log4net – qkhanhpro May 04 '17 at 11:19

0 Answers0