1

I have a server application that processes messages. We need to keep a separate log file for each message process. We have used Adam's answer to a relevant question: Logging to an individual log file for each individual thread

The only problem is that when the process is done, the repository needs to be disposed. We call

log4net.LogManager.ShutdownRepository(logFileName + "Repository");

when the process ends, but the LogManager still references the created repository. So, every call adds a new repository, thus causing increasing memory.

Is there a way to properly dispose the repository? Sorry for opening a new question, I don't have enough rep to comment on an answer.

Community
  • 1
  • 1
TomTee
  • 91
  • 9

1 Answers1

0

The loggers defined in your repository are not really supposed to be cleaned up. However there is a way if the repository you are using is a Hierarchy (cast it to be sure); just call the Clear method.

A note of warning: only do this if you don't need the Repository anymore, the documentation warns that :

This call will clear all logger definitions from the internal hashtable. Invoking this method will irrevocably mess up the logger hierarchy.

You should really know what you are doing before invoking this method.

(emphasis not mine :) )

samy
  • 14,832
  • 2
  • 54
  • 82
  • Calling [Shutdown](https://logging.apache.org/log4net/release/sdk/log4net.Repository.Hierarchy.Hierarchy.Shutdown.html) on Repository, clears the appenders. Calling [Clear](https://logging.apache.org/log4net/release/sdk/log4net.Repository.Hierarchy.Hierarchy.Clear.html) clears the loggers. But still the repository exists in the internal collection of LogManager, and the collection constantly increases. – TomTee Sep 30 '14 at 18:21
  • Too bad, I thought this coul be sufficient for you needs. Then you have to create your own IRepositorySelector, and provide access to its Repository collection; there is no access to the Repository collection in the current selectors. – samy Sep 30 '14 at 22:28