【发布时间】:2013-05-06 22:12:58
【问题描述】:
目前我有 LogWrapper 类,它初始化 NLog 并向其发送 Info/Debug/Warning 等。
所以其他类中的每个方法都是从
开始的LogWrapper.Informational(string.Format(" {0} starts {1}", MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name));
在 LogWrapper 中时:
private static readonly Logger s_log = LogManager.GetCurrentClassLogger();
public static void Informational(string fmt, Exception exception)
{
s_log.Info("{0} {1}",fmt, exception.ToString());
}
问题在于,由于调用类与访问日志包装器的类不同,日志总是显示 LogWrapper 的 namespace.methodname,因此对 MethodBase 进行了无用的调用。
有什么方法可以从实际访问 NLog 的不同类中调用函数?
谢谢
【问题讨论】: