tags:

views:

48

answers:

1

I am working on .net framework 3.5 using C# in windows XP as administrator user, using log4net for .net framework 2.0 binary reference

I had tried http://stackoverflow.com/questions/2620056/what-am-i-missing-with-log4net-no-log-file-created but it does`t work for me.

i add the following into AssemblyInfo.cs

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

And created a file "Log4Net.config" as below, however, when i run my console application, cannot find any log file in my project. what do i miss???

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

    <!-- 
            log4net documentation http://logging.apache.org/log4net/
            Logging levels in order of increasing priority:
                * ALL
                * DEBUG
                * INFO
                * WARN
                * ERROR
                * FATAL
                * OFF
        -->

    <appender name="DebugLog" type="log4net.Appender.FileAppender">
      <file value="MyLog_debug.log" />
      <appendToFile value="true" />
      <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
      <maximumFileSize value="5MB" />
      <filter type="log4net.Filter.LevelRangeFilter">
        <levelMin value="DEBUG" />
        <levelMax value="DEBUG" />
      </filter>
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%newline%date %-5level %logger - %message%newline" />
      </layout>
    </appender>

    <appender name="InfoLog" type="log4net.Appender.RollingFileAppender">
      <file value="MyLog_info.log" />
      <appendToFile value="true" />
      <rollingStyle value="Composite" />
      <datePattern value="yyyyMMdd" />
      <maxSizeRollBackups value="7" />
      <maximumFileSize value="5MB" />
      <filter type="log4net.Filter.LevelRangeFilter">
        <levelMin value="INFO" />
        <levelMax value="WARN" />
      </filter>
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%newline%date %-5level %logger - %message%newline" />
      </layout>
    </appender>

    <appender name="ErrorLog" type="log4net.Appender.RollingFileAppender">
      <file value="MyLog_error.log" />
      <appendToFile value="true" />
      <rollingStyle value="Composite" />
      <datePattern value="yyyyMMdd" />
      <maxSizeRollBackups value="30" />
      <maximumFileSize value="5MB" />
      <filter type="log4net.Filter.LevelRangeFilter">
        <levelMin value="ERROR" />
        <levelMax value="FATAL" />
      </filter>
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%newline%date %-5level %logger - %message%newline" />
      </layout>
    </appender>

    <!-- Set the default logging level and add the active appenders -->
    <root>
      <level value="ALL" />
      <appender-ref ref="DebugLog" />
      <appender-ref ref="InfoLog" />
      <appender-ref ref="ErrorLog" />
    </root>

  </log4net>
</configuration>
+1  A: 

Make sure the config file is being copied to the output directory.

If you're using Visual Studio, go to the 'Log4Net.config' properties, and make sure that the 'Copy to Output Directory' is set to 'Copy always' or 'Copy if newer'. Otherwise, just make sure you copy the config file to the output directory.

Also, log4net.Appender.FileAppender does not have a 'maximumFileSize' property, so you'll want to remove that from your configuration file.

Joviee