错误的文件和行log4net的包装 [英] wrong file and line in log4net wrapper

查看:158
本文介绍了错误的文件和行log4net的包装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个log4net的包装

I wrote a log4net wrapper

public class Log4NetWrapper : ILogger
{
    private readonly log4net.ILog logger;

    public Log4NetWrapper(string loggerName)
    {
        logger = log4net.LogManager.GetLogger(loggerName);
    }

    public void Debug(string message, params object[] values)
    {
        logger.DebugFormat(message, values);
    }


    public bool IsDebugEnabled {get { return logger.IsDebugEnabled; } }

    ...

}

问题是,登录时,我得到了行和文件是包装,而不是消息的实际位置。

the problem is that the line and file I get when logging is of the wrapper and not the actual location of the message.

推荐答案

这是由设计,如果你有兴趣,其中一个例外是,你应该记录异常对象或其堆栈跟踪成员,首先抛出,如果你已经配置了log4net的文件追加程序,以显示文件和行的代码行和文件消息从,这是正常的,你觉得你的包装,但记录异常和堆栈跟踪时,你会找到正确的内容写的。

this is by design, if you are interested in line and file where an exception is thrown in the first place you should log the exception object or its stacktrace member, if you have configured the log4net file appender to show the file and line where the message is been written from, it is normal that you find your wrapper, but when logging exceptions and stacktrace you will find the correct content.

在我们的追加程序,我们有以下几点,所以我们甚至不显示的包装类名或文件/行...

in our appenders we have the following, so we do not even show the wrapper class name or file/line...

<log4net>
<appender name="FileAppender" type="log4net.Appender.RollingFileAppender">
    <threshold value="ALL"/>
    <immediateFlush>true</immediateFlush>
    <lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>
    <encoding value="utf-8"/>
    <file value="D:\Axis\RPP\Logs\myLogFile.log" />
    <appendToFile value="true"/>
    <rollingStyle value="Date" />
    <maxSizeRollBackups value="30" />
    <maximumFileSize value="25MB" />
    <staticLogFileName value="true"/>
    <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="[%property{log4net:HostName}] - %username%newline%utcdate - %-5level - %message%newline"/>
    </layout>
</appender>

<root>
    <priority value="ALL"/>
    <appender-ref ref="FileAppender"/>
</root>



这篇关于错误的文件和行log4net的包装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆