Tor Sterner
Tor Sterner

Reputation: 75

log4net creates and fills files with repeated text

We have several ASP.NET MVC instances which uses log4net. The instances logs information very rarely to the specified log file. But still generates a HUGE amount of log4net files filled with what I assume is logging of the actual log4net setup.

The generated files are in the form [guid]log4net.txt. Example: 6cec7387-2ca2-4186-b40d-35bf1f3fad39log4net.txt

And contains this sort of information repeated to several mb files:

log4net: log4net assembly [log4net, Version=1.2.11.0, Culture=neutral,                                          PublicKeyToken=669e0ddf0bb1aa2a]. Loaded from [C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\5ce477cb\c777cea8\assembly\dl3\8f934d8e\ab938bbc_bfb9ce01\log4net.dll]. (.NET Runtime [4.0.30319.18052] on Microsoft Windows NT 6.1.7601 Service Pack 1)
log4net: defaultRepositoryType [log4net.Repository.Hierarchy.Hierarchy]
log4net: Creating repository for assembly [<application assembly>, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]
log4net: Assembly [<application assembly>, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] Loaded From [C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\5ce477cb\c777cea8\assembly\dl3\7ff992c2\7d13e38d_9ac9ce01\<application assembly>.dll]
log4net: Assembly [<application assembly>, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] does not have a RepositoryAttribute specified.
log4net: Assembly [<application assembly>, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null] using repository [log4net-default-repository] and repository type [log4net.Repository.Hierarchy.Hierarchy]
log4net: Creating repository [log4net-default-repository] using type [log4net.Repository.Hierarchy.Hierarchy]
log4net: configuring repository [log4net-default-repository] using file [<application path>\Web.config] watching for file updates
log4net: configuring repository [log4net-default-repository] using file [<application path>\Web.config]
log4net: configuring repository [log4net-default-repository] using stream
log4net: loading XML configuration
log4net: Configuring Repository [log4net-default-repository]
log4net: Configuration update mode [Merge].
log4net: Logger [root] Level string is [DEBUG].
log4net: Logger [root] level set to [name="DEBUG",value=30000].
log4net: Loading Appender [LogFileAppender] type: [log4net.Appender.RollingFileAppender]
log4net: Parameter [file] specified subtype [log4net.Util.PatternString]
log4net: Converter [literal] Option [.\\App_Data\\Log[] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [processid] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [literal] Option []] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Performing additional conversion of value from [PatternString] to [String]
log4net: Setting Property [File] to String value [.\\App_Data\\Log[7392]]
log4net: Setting Property [AppendToFile] to Boolean value [True]
log4net: Setting Property [RollingStyle] to RollingMode value [Size]
log4net: Setting Property [MaxSizeRollBackups] to Int32 value [10]
log4net: Setting Property [MaximumFileSize] to String value [10MB]
log4net: Setting Property [StaticLogFileName] to Boolean value [True]
log4net: Setting Property [LockingModel] to object [log4net.Appender.FileAppender+MinimalLock]
log4net: Converter [message] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [newline] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Setting Property [ConversionPattern] to String value [%-5p%d{yyyy-MM-dd hh:mm:ss} – %m%n]
log4net: Converter [p] Option [] Format [min=5,max=2147483647,leftAlign=True]
log4net: Converter [d] Option [yyyy-MM-dd hh:mm:ss] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [literal] Option [ – ] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [m] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Converter [n] Option [] Format [min=-1,max=2147483647,leftAlign=False]
log4net: Setting Property [Layout] to object [log4net.Layout.PatternLayout]
log4net: Searched for existing files in [<application path>\App_Data]
log4net: curSizeRollBackups starts at [0]
log4net: Opening file for writing [<application path>\App_Data\Log[7392]] append [True]
log4net: reated Appender [LogFileAppender]
log4net: Adding appender named [LogFileAppender] to logger [root].
log4net: Hierarchy Threshold []
log4net: configuring repository [log4net-default-repository] using .config file section
log4net: Application config file is [<application path>\web.config]

The relevant part of the web.config looks like this:

  <log4net>
    <root>
      <level value="DEBUG" />
      <appender-ref ref="LogFileAppender" />
    </root>
    <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
      <file type="log4net.Util.PatternString" value=".\\App_Data\\Log[%processid]" />
      <param name="AppendToFile" value="true" />
      <rollingStyle value="Size" />
      <maxSizeRollBackups value="10" />
      <maximumFileSize value="10MB" />
      <staticLogFileName value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%-5p%d{yyyy-MM-dd hh:mm:ss} – %m%n" />
      </layout>
    </appender>
  </log4net>
  <system.diagnostics>
    <trace autoflush="true">
      <listeners>
        <add name="textWriterTraceListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="<logs path>\log4net.txt" />
      </listeners>
    </trace>
  </system.diagnostics>

And the Log is configured by:

XmlConfigurator.Configure();

And used as:

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

By regular calls to Warn etc.

We have tried to change the settings of the LogFileAppender to use different files in different processes (as in the example). And made sure there is no errors or conflics in the generated files. Logging works as intended to the correct files, the issue is that the generated files described above is about 1 GB/day which fills our server pretty fast. =/

How do we stop log4net generating these files? (or reduce it to only generate one with a size limit)

Respond if you have any questions or need more information.

Upvotes: 2

Views: 614

Answers (1)

CodeCaster
CodeCaster

Reputation: 151594

It looks like you've enabled log4net's internal debugging.

You can do that from the web.config, by adding an appSettings element:

<add key="log4net.Internal.Debug" value="true" />

Or from code:

log4net.Util.LogLog.InternalDebugging = true;

If this happens anywhere in your program, log4net will start logging each action it takes.

Upvotes: 1

Related Questions