0

I'm trying to integrate log4net dll in one of the project. it works fine when i run it locally.However, when i try to deploy the project as COM Object remotely, it doesn't create any log file at given location. FYI, i'm using .net framework 2 for this project

I have made all the changes mentioned on the following link but still no luck

  1. Log4net does not write the log file
  2. Log4net Not Creating Log File

AssesmblyInfo.cs

[assembly: log4net.Config.XmlConfigurator(ConfigFile = "app.config", Watch = true)]

app.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/>
  </configSections>

  <log4net>
    <appender name="TestAppender" type="log4net.Appender.RollingFileAppender">
      <file type="log4net.Util.PatternString" value="D:\\log\\SchT%date{yyyyMMdd}.log" />
      <encoding value="utf-8"/>
      <appendToFile value="true"/>
      <rollingStyle value="Date"/>
      <!--<rollingStyle value="Size" />
      <maxSizeRollBackups value="5" />
      <maximumFileSize value="5MB" />
      <staticLogFileName value="true" />-->
      <datePattern value="yyyyMMdd" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date %level [%thread] %type.%method - %message%n"/>
      </layout>
    </appender>
    <root>
      <level value="All"/>
      <!-- If the following line is not included the log file will not be created even if log4net is configured with this file. -->
      <appender-ref ref="TestAppender"/>
    </root>
  </log4net>

  <startup>

    <supportedRuntime version="v2.0.50727"/>
  </startup>
</configuration>

Controller

log4net.Config.XmlConfigurator.Configure();
           _log = log4net.LogManager.GetLogger
    (System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

When i debug it, _log gets all log levels as false. I suspect, app.config doesn't load properly that's why file is not created.

Any idea?

Community
  • 1
  • 1
user1030128
  • 411
  • 9
  • 23
  • 1
    _"when i try to deploy the project as COM Object remotely"_ - can you give more details about that? – stuartd Jan 23 '17 at 15:22
  • 1
    It's probably looking for app.config in the base directory of the AppDomain that hosts log4net. If this is a COM object, the base directory is likely to be the directory where the unmanaged executable that loads the COM object is located. Try examining AppDomain.CurrentDomain.BaseDirectory when you're debugging. – Joe Jan 23 '17 at 15:57
  • Thanks Joe. It works. – user1030128 Jan 24 '17 at 07:24

0 Answers0