According to the log4net documentation here (see under log4net.Core.ILogger ), you can use the log method on the ILogger interface.
private static ILog logger = LogManager.GetLogger( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); logger.Logger.Log(logger.GetType(),LogLevel.Debug,"Something went wrong", ex);
The Type parameter is used for log4net to define the boundary in the call stack between the logging code and the application code. If you have enabled method logging, log4net moves the call stack until the DeclaringType of the MethodInfo method on the stack is equal to the passed type (the type in the log call above). When it finds that DeclaringType, the next method in the call stack is the actual call method (application code).
You can also use overloading, which takes a LoggingEvent structure.
The documentation also says that the Log method is intended for use by shells. I don’t know whether this should be considered as an “informational” message or a strong suggestion not to use it directly.
If you want to make all your log calls using the log method, you can change the code in which you get the logger so that it is (so that you can exclude the use of the Logger property for each log call):
private static ILogger logger = LogManager.GetLogger( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType).Logger; logger.Log(logger.GetType(),LogLevel.Debug,"Something went wrong", ex);
wageoghe
source share