为什么没有在log4net的跟踪级别? [英] Why isn't there a trace level in log4Net?
问题描述
我只是想知道为什么没有在跟踪级别 log4net的。此级别似乎是失踪,我有时觉得有必要使用它,例如,哪些事件在应用程序中执行输出。此功能的log4j 的一部分。
I was just wondering why there isn't a trace level in log4Net. This level seems to be missing and I sometimes feel the need to use it, for example to output what events are being executed in an application. This feature is a part of log4J.
我知道我可以创建一个自定义级别类似谈到的这里但我不希望把时间和精力的东西,我觉得应该是库本身的一部分。
I know I can create a custom level like is talked about here but I don't want to put time and effort in something I feel should be part of the library itself.
你知道它实现这或log4net的扩展库,这是为什么不港口的一部分.NET?
Do you know about a log4net extension library which implements this or why this wasn't a part of the port to .net ?
推荐答案
您可以添加一个详细(或跟踪级别)通过使用扩展方法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
{
private static readonly log4net.ILog log =
log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
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);
}
}
用法示例:
Usage example:
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屋!