包装Log4net时如何记录MethodName? [英] How to log MethodName when wrapping Log4net?
本文介绍了包装Log4net时如何记录MethodName?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已将 Log4net 包装在静态包装器中并想记录
I have wrapped Log4net in a static wrapper and want to log
loggingEvent.LocationInformation.MethodName
loggingEvent.LocationInformation.ClassName
但是我得到的只是我的包装器的名称.
However all I get is the name of my wrapper.
如何使用 forwardingappender 和像
How can I log that info using a forwardingappender and a static wrapper class like
Logger.Debug("Logging to Debug");
Logger.Info("Logging to Info");
Logger.Warn("Logging to Warn");
Logger.Error(ex);
Logger.Fatal(ex);
推荐答案
嗯,错误出现在我的 appender 中的某个地方,但为了完整起见,我提供了尽我所知的答案:
Well the error was somewhere in my appender but for completeness ill include the answer to the best of my knowledge:
你需要的 Facade 应该包装 ILogger 而不是 ILog
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);
}
}
这篇关于包装Log4net时如何记录MethodName?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文