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

发布于 2024-08-04 00:00:24 字数 538 浏览 6 评论 0原文

我只是想知道为什么没有 跟踪级别 在 log4Net 中。这个级别似乎缺失,我有时觉得需要使用它,例如输出应用程序中正在执行的事件。此功能是 log4J 的一部分

我知道我可以创建一个自定义级别,就像此处讨论的那样,但我不想这样做把时间和精力花在我认为应该成为图书馆本身一部分的事情上。

您是否知道实现此功能的 log4net 扩展库或者为什么这不是 .net 端口的一部分?

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.

Do you know about a log4net extension library that implements this or why this wasn't a part of the port to .net ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小瓶盖 2024-08-11 00:00:24

您可以使用扩展方法向 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

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);
    }

}

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

虫児飞 2024-08-11 00:00:24

log4net.ILog 接口仅公开 Fatal、Error、Warn、Info 和 Debug 级别的方法和属性。

我同意这有点限制,并且希望在那里看到更多的级别。但最佳的关卡数可能是“比当前的关卡数多一级”——你总会发现自己偶尔想要多一级。

The log4net.ILog interface only exposes methods and properties for Fatal, Error, Warn, Info and Debug levels.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文