我可以毫无问题地记录信息消息,但不知道如何记录详细消息。 任何帮助都会受到欢迎。
我的问题是:
loggingEvent.Level可以在Format函数中检查。可能的值包括信息、调试、错误、详细。还有更多,但这些是我将主要使用的。
实际的日志对象只有以下方法:
日志信息
日志.调试
日志警告
日志错误
如您所见 - 没有冗长!
那么如何记录详细消息,这与调试不同
提前致谢
最佳答案
您可以使用扩展方法向 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);
}
}
使用示例:
public class ClientDAO
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(ClientDAO));
public void GetClientByCode()
{
log.Trace("your verbose message here");
//....
}
}
来源:
http://www.matthewlowrance.com/post/2010/07/14/Logging-to-Trace-Verbose-etc-with-log4net.aspx
关于Log4net,如何记录详细消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2279773/