Log4net,如何记录详细消息? [英] Log4net, how to log a verbose message?
问题描述
我可以毫无问题地记录信息消息,但无法弄清楚如何记录详细消息. 任何帮助都将受到欢迎.
I can log info messages without a problem, but can't figure out how to log verbose messages. Any help would be welcomed.
我的问题是:
loggingEvent.Level.可能的值包括信息",调试",错误",详细".还有更多,但是这些是我将主要使用的.
loggingEvent.Level can be checked in the Format function. The possible values are amongst others, Info, Debug, Error, Verbose. There are more, but these are the ones I'll be using mostly.
实际的日志对象仅具有以下方法:
The actual log object only has the following methods:
Log.Info
Log.Debug
Log.Warn
Log.Error
Log.Info
Log.Debug
Log.Warn
Log.Error
如您所见-没有冗长的内容!
As you can see - no verbose!
所以我该如何记录一条冗长的消息,这与调试不同
So how can I Log a verbose message, this is different to debug
预先感谢
推荐答案
您可以使用扩展方法将详细(或跟踪级别)添加到log4net.这就是我正在使用的:
You can add a Verbose (or Trace level) to log4net by using extension methods. This is what I'm using:
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,如何记录详细消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!