1

I am using log4net to perform daily logging.
I realize that log4net doesn't support deleting old files in this fashion.

I am trying to write my own method to accomplish this task, however I am no sure how to read the log4net settings from the web.config file.

I've tried:

var log4NetData = ConfigurationManager.GetSection("log4net");

However I get this as my results:

The type 'System.Configuration.ConfigXmlElement' exists in both 'System.Configuration.dll' and 'System.dll'

How can I read the log4net node from my web.config?

stuartd
  • 70,509
  • 14
  • 132
  • 163
John Doe
  • 3,053
  • 17
  • 48
  • 75

1 Answers1

0

Actually Log4Net can update the same file always (this way, there is no need to delete it and create another one). I'm using log4Net to log always the same file n times in a hour. My configurations:

private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

app.config:

<configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
  </configSections>  
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
  <log4net>
    <root>
      <level value="ALL" />
      <appender-ref ref="MyFileAppender" />
    </root>
    <appender name="MyFileAppender" type="log4net.Appender.FileAppender">
      <file value="application.log" />
      <appendToFile value="true" />
      <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date %level - %message%newline" />
      </layout>
    </appender>
  </log4net>