log4net的不是DLL工作 [英] log4net not working in dll

查看:108
本文介绍了log4net的不是DLL工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前具有让log4net的一个特定的DLL中正常工作的问题。我目前使用log4net的其他DLL被我的测试应用程序调用,日志记录这些dll内内也是我的测试应用程序工作正常。这是我遇到的麻烦这一个特定的DLL。下面是我遇到的麻烦的DLL的代码段。

  //这是从ABC.dll 
公共类的SessionFactory
{
受保护的静态ISessionFactory SessionFactory的;
私人静态只读的ILog日志= LogManager.GetLogger(typeof运算(SessionFactory的));

私有静态无效的init()
{

{
//读取从hibernate.xml.cfg或app.config中$ B的配置$ b配置normalConfig =新配置()配置()。
ConfigureNhibernateValidator(normalConfig);

log.Debug(初始化会话工厂);

SessionFactory的= Fluently.Configure(normalConfig)
.Mappings(M = GT;
m.FluentMappings
.AddFromAssemblyOf< OrderHeaderMap>()
。 Conventions.AddFromAssemblyOf< PascalCaseColumnNameConvention>())
.ProxyFactoryFactory(NHibernate.ByteCode.LinFu.ProxyFactoryFactory,NHibernate.ByteCode.LinFu)
.BuildSessionFactory();

log.Debug(说完初始化会话工厂);
}
赶上(异常前)
{
//代码没有显示
}
}
}

在我的测试程序,我呼吁:

  log4net.Config.XmlConfigurator.Configure(); 

下面是我App.config文件我log4net的配置:



<预类=郎咸平的XML prettyprint-覆盖> <结构>
< configSections>
<节名称=log4net的TYPE =log4net.Config.Log4NetConfigurationSectionHandler,log4net的/>
< / configSections>
<&log4net的GT;
< - 所有|调试|信息| WARN | ERROR |致命| OFF - >!;
<根和GT;
<电平值=DEBUG/>
<附加目的地-REF REF =SPEEDTEST/>
< /根>

<! - 这是NHibernate的使用到的所有SQL语句推送到一个默认的记录 - >
<记录器名称=NHibernate.SQL相加=false的>
<电平值=DEBUG/>
<附加目的地-REF REF =NHibernateConsoleLog/>
<附加目的地-REF REF =NHibernateFileLog/>
< /记录器>

<! - 这是NHibernate的使用到所有的调试类型信息推送到一个默认的记录 - >
<记录器名称=NHibernate的相加=false的>
<电平值=DEBUG/>
<附加目的地-REF REF =NHibernateFileLog/>
< /记录器>

<追加程序名称=NHibernateConsoleLogTYPE =log4net.Appender.TraceAppender>
<布局类型=log4net.Layout.PatternLayout>
< conversionPattern值=%DATE [%线程]%-5level%记录[%产权{} NDC - %讯息%换行/>
< /布局>
< /附加器>

<追加程序名称=NHibernateFileLogTYPE =log4net.Appender.RollingFileAppender>
<文件值=日志/ nhibernate.txt/>
< appendToFile值=真/>
< rollingStyle值=大小/>
< maxSizeRollBackups值=10/>
< maximumFileSize值=10MB/>
< staticLogFileName值=真/>
<布局类型=log4net.Layout.PatternLayout>
< conversionPattern值=%d个{HH:MM:SS.FFF} [%T]%-5p%C - %M%N/>
< /布局>
< /附加器>

<追加程序名称=SPEEDTESTTYPE =log4net.Appender.RollingFileAppender>
<文件值=日志/ SpeedTest.txt/>
< appendToFile值=真/>
< rollingStyle值=大小/>
< maxSizeRollBackups值=10/>
< maximumFileSize值=10MB/>
< staticLogFileName值=真/>
<布局类型=log4net.Layout.PatternLayout>
< conversionPattern值=%d个{HH:MM:SS.FFF} [%T]%-5p%C - %M%N/>
< /布局>
< /附加器>
< / log4net的>

< /结构>



再次登录使用SPEEDTEST的appender但上面的代码中记录我的测试应用程序中工作正常代码是行不通的。我设置断点以上时,初始化记录器上,它似乎打它。如果需要的话我可以张贴log4net的调试输出,但我真的没有看到多少。只是让我知道,如果你需要它,我将发布。



任何建议,为什么日志不被记录在上面的代码片断?


解决方案

看来,这个问题是从我改变了目录,以我所有的外部依赖所产生的(log4net的是其中之一)一段时间回来TFS中。我所做的只是将我的所有引用在我的Visual Studio项目从我的新的依赖文件夹重新添加和一切工作后,这个预期。感谢所有那些帮助这里。


I'm currently having issues with getting log4net to work within a particular dll. I'm currently using log4net in other dlls being called by my test app and logging is working fine within those dlls and also within my test app. It's this one particular dll that I'm having trouble with. Here is snippet of code from the dll I'm having trouble with.

//This is from ABC.dll
public class SessionFactory
{
    protected static ISessionFactory sessionFactory;
    private static readonly ILog log = LogManager.GetLogger(typeof(SessionFactory));

    private static void Init()
    {
        try
        {
            //Read the configuration from hibernate.xml.cfg or app.config
            Configuration normalConfig = new Configuration().Configure();
            ConfigureNhibernateValidator(normalConfig);

            log.Debug("Initializing session factory");

            sessionFactory = Fluently.Configure(normalConfig)
              .Mappings(m =>
                  m.FluentMappings
                  .AddFromAssemblyOf<OrderHeaderMap>()
                  .Conventions.AddFromAssemblyOf<PascalCaseColumnNameConvention>())
               .ProxyFactoryFactory("NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu")
              .BuildSessionFactory();

            log.Debug("Finished initializing the session factory");
        }
        catch(Exception ex)
        {
            //Code not shown
        }
    }
}

In my test app I am calling:

log4net.Config.XmlConfigurator.Configure();

Here is my log4net configuration in my App.config file:

<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
  </configSections>
  <log4net>
    <!-- ALL|DEBUG|INFO|WARN|ERROR|FATAL|OFF -->
    <root>
      <level value="DEBUG"/>
      <appender-ref ref="SpeedTest"/>
    </root>

    <!-- This is a default logger that nhibernate uses to push out all the SQL statements to-->
    <logger name="NHibernate.SQL" additivity="false">
      <level value="DEBUG"/>
      <appender-ref ref="NHibernateConsoleLog"/>
      <appender-ref ref="NHibernateFileLog"/>
    </logger>

    <!-- This is a default logger that nhibernate uses to push out all the debugging type information to-->
    <logger name="NHibernate" additivity="false">
      <level value="DEBUG"/>
      <appender-ref ref="NHibernateFileLog"/>
    </logger>

    <appender name="NHibernateConsoleLog" type="log4net.Appender.TraceAppender">
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline"/>
      </layout>
    </appender>

    <appender name="NHibernateFileLog" type="log4net.Appender.RollingFileAppender">
      <file value="Logs/nhibernate.txt" />
      <appendToFile value="true" />
      <rollingStyle value="Size" />
      <maxSizeRollBackups value="10" />
      <maximumFileSize value="10MB" />
      <staticLogFileName value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%d{HH:mm:ss.fff} [%t] %-5p %c - %m%n"  />
      </layout>
    </appender>

    <appender name="SpeedTest" type="log4net.Appender.RollingFileAppender">
      <file value="Logs/SpeedTest.txt" />
      <appendToFile value="true" />
      <rollingStyle value="Size" />
      <maxSizeRollBackups value="10" />
      <maximumFileSize value="10MB" />
      <staticLogFileName value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%d{HH:mm:ss.fff} [%t] %-5p %c - %m%n"  />
      </layout>
    </appender>
  </log4net>

</configuration>

Again logging is working fine within my test application using the SpeedTest appender but the logging within the above snippet of code is not working. I set breakpoints above on when it initializes the logger and it seems to hit it. I can post the log4net debug output if necessary but I didn't really see much. Just let me know if you need it and I will post.

Any suggestions as to why logging is not being recorded in the above snippet of code?

解决方案

It seems that this issue was stemming from me changing the directory to all my external dependencies (log4net being one of them) awhile back in TFS. All I did was drop all my references in my visual studio project and re-add them from my new dependencies folder and everything worked as expected after this. Thanks for all those that helped here.

这篇关于log4net的不是DLL工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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