How to log MethodName when wrapping Log4net?
What about the %M
and %C
variables?
http://logging.apache.org/log4net/log4net-1.2.11/release/sdk/log4net.Layout.PatternLayout.html
Usage, something like:
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%M %C] - %message%newline" />
</layout>
Doesn't that do what you are after?
I would simply use something like %stacktrace{2}
as a conversion pattern.
Example of output:
MyNamespace.ClassName.Method > Common.Log.Warning
where MyNamespace.ClassName.Method
is a method that is calling my wrapper and Common.Log.Warning
is a method of the wrapper class.
Conversion patterns can be found here.
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);
}
}