How to log MethodName when wrapping Log4net?

后端 未结 10 1732
说谎
说谎 2020-11-29 23:41

I have wrapped Log4net in a static wrapper and want to log

loggingEvent.LocationInformation.MethodName
loggingEvent.LocationInformation.ClassName
         


        
10条回答
  •  孤街浪徒
    2020-11-30 00:36

    Well the error was somewhere in my appender but for completeness ill include the answer to the best of my knowledge:

    the Facade you need should wrap ILogger and NOT ILog

     public static class Logger
     {
        private readonly static Type ThisDeclaringType = typeof(Logger);
        private static readonly ILogger defaultLogger;
    
        static Logger()
        {
          defaultLogger =
            LoggerManager.GetLogger(Assembly.GetCallingAssembly(),"MyDefaultLoggger");
    

    ...

        public static void Info(string message)
        {
            if (defaultLogger.IsEnabledFor(infoLevel))
            {
                defaultLogger.Log(typeof(Logger), infoLevel, message, null);
            }
        }
    

提交回复
热议问题