简体   繁体   English

为什么在log4Net中没有跟踪级别?

[英]Why isn't there a trace level in log4Net?

I was just wondering why there isn't a trace level in log4Net. 我只是想知道为什么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 . 此功能是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. 我知道我可以像在这里讨论的那样创建自定义级别但是我不想花时间和精力在我认为应该属于库本身的事情上。

Do you know about a log4net extension library that implements this or why this wasn't a part of the port to .net ? 您是否知道实现此功能的log4net扩展库,或者为什么它不是.net端口的一部分?

You can add a Verbose (or Trace level) to log4net by using extension methods. 您可以使用扩展方法将详细(或跟踪级别)添加到log4net。 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);
    }

}

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");
        //....
    }
}

Source: 资源:

http://www.matthewlowrance.com/post/2010/07/14/Logging-to-Trace-Verbose-etc-with-log4net.aspx http://www.matthewlowrance.com/post/2010/07/14/Logging-to-Trace-Verbose-etc-with-log4net.aspx

The log4net.ILog interface only exposes methods and properties for Fatal, Error, Warn, Info and Debug levels. log4net.ILog接口仅公开致命,错误,警告,信息和调试级别的方法和属性。

I agree this is a bit limiting and would like to see one more level in there. 我同意这是一个限制,希望在那里再看到一个层次。 But then the optimal number of levels is probably "one more than the current number of levels" - you'll always find yourself occasionally wanting one more level. 但是,最佳级别数可能是“比当前级别数多一”-您总是会发现自己偶尔需要一个更高级别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM