我可以毫无问题地记录信息消息,但无法弄清楚如何记录详细消息.任何帮助都会受到欢迎.
我的问题是:
可以在Format函数中检查loggingEvent.Level.可能的值包括Info,Debug,Error,Verbose等.还有更多,但这些是我将主要使用的.
实际的日志对象只有以下方法:
Log.Info
Log.Debug
Log.Warn
Log.Error
正如你所看到的 - 没有冗长!
那么如何记录详细消息,这与调试不同
提前致谢
Wag*_*lva 30
您可以使用扩展方法向log4net添加详细(或跟踪级别).这就是我正在使用的:
public static class ILogExtentions
{
public static void Trace(this ILog log, string message, Exception exception)
{
log.Logger.Log(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType,
log4net.Core.Level.Trace, message, exception);
}
public static void Trace(this ILog log, string message)
{
log.Trace(message, null);
}
public static void Verbose(this ILog log, string message, Exception exception)
{
log.Logger.Log(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType,
log4net.Core.Level.Verbose, message, exception);
}
public static void Verbose(this ILog log, string message)
{
log.Verbose(message, null);
}
}
Run Code Online (Sandbox Code Playgroud)
用法示例:
public class ClientDAO
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(ClientDAO));
public void GetClientByCode()
{
log.Trace("your verbose message here");
//....
}
}
Run Code Online (Sandbox Code Playgroud)
资源:
http://www.matthewlowrance.com/post/2010/07/14/Logging-to-Trace-Verbose-etc-with-log4net.aspx