C# application log4net log file not created when used in C++/CLI

六月ゝ 毕业季﹏ 提交于 2020-04-13 16:51:50

问题


I've written a C# dll - foo.dll - that uses log4net for logging. The dll is then used in a C++ application via a C++\CLI wrapper. The C++ application works perfectly, however the log file is not created. When I use this dll in a testing C# application (that uses the original C# dll) the log file is create without problems.

This configuration is set in foo.dll.config:

  <configSections>    
    <section name="log4net"
      type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
  </configSections>
  <log4net>
    <root>
        <level value="DEBUG" />
        <appender-ref ref="RollingFileAppender" />
    </root>
    <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
        <file value="D:\\foo.log" />
        <appendToFile value="true" />
        <rollingStyle value="Size" />
        <maxSizeRollBackups value="5" />
        <maximumFileSize value="10MB" />
        <staticLogFileName value="true" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%date [%thread] %level - %message%newline" />
        </layout>
    </appender>
  </log4net>

Other configuration are read without problems from the foo.dll.config file and the C++ application has writing permissions for the log directory.

Any idea what I'm missing here?


回答1:


I re-write my comment as answer.

You must try to define an app.config file for your C++ application (not only for the dll itself), and include on it the log4net configuration.



来源:https://stackoverflow.com/questions/24436406/c-sharp-application-log4net-log-file-not-created-when-used-in-c-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!