Wag*_*lva 52
您可以使用扩展方法向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
nos*_*nos 13
还有就是在log4net.Core.Level类跟踪级别http://logging.apache.org/log4net/release/sdk/html/F_log4net_Core_Level_Trace.htm
log4net.ILog接口仅公开Fatal,Error,Warn,Info和Debug级别的方法和属性.
我同意这有点限制,并希望在那里再看一个级别.但是,最佳等级数可能是"比目前的等级数多一个" - 你总会发现自己偶尔会想要一个等级.
| 归档时间: |
|
| 查看次数: |
13164 次 |
| 最近记录: |