Hi guys firstly excuse me for my bad english, ill try my very best to be as accurate as possible.
I am using log4net 3.5 in .NET Framework 4.5.
The Problem I am actually facing is a very common. log4net is logging everything twice. It isn't configured with a xml file, i am using a static Class to do this.
/// <summary>
/// Diese Klasse konfiguriert die Logs bei ausführungszeit
/// </summary>
public static class LoggerSetup
{
static LoggerSetup()
{
_fileDirectory = @"Log\";
_archiveInterval = 7;
Setup();
}
/// <summary>
/// Der Ort wo das Logfile gespeichert wird
/// </summary>
public static string FileDirectory
{
get
{
return _fileDirectory;
}
set
{
_fileDirectory = value;
Setup();
}
}
private static string _fileDirectory;
/// <summary>
/// Wieviele Tage die Logfiles im Speicher bleiben
/// </summary>
public static int ArchiveInterval
{
get
{
return _archiveInterval;
}
set
{
if (value <= 0)
value = 1;
_archiveInterval = value;
Setup();
}
}
private static int _archiveInterval;
private static void Setup()
{
// Here the hierarchy object is taken
Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
// Pattern Layout defined
PatternLayout patternLayout = new PatternLayout();
patternLayout.ConversionPattern = "%date [%-5level] %message%newline";
patternLayout.ActivateOptions();
// configurating the RollingFileAppender object
RollingFileAppender roller = new RollingFileAppender();
roller.AppendToFile = true;
roller.File = FileDirectory + "Log.log";
roller.StaticLogFileName = true;
roller.PreserveLogFileNameExtension = true;
roller.LockingModel = new FileAppender.MinimalLock();
roller.Layout = patternLayout;
roller.MaxSizeRollBackups = ArchiveInterval;
roller.RollingStyle = RollingFileAppender.RollingMode.Date;
roller.DatePattern = "_yyyy-MM-dd";
roller.ActivateOptions();
// Here it is added only once to the Root
hierarchy.Root.AddAppender(roller);
hierarchy.Root.Level = Level.Info;
hierarchy.Configured = true;
}
}
I have already been looking up some other pages, such as
In those Questions i have found, the thread there was alaways double adding an appender, mostly they have been added to a root and to a logger object.
As you can see in the code above I am doing it only once... Any Ideas? the Setup() method is called everytime a Property is updated, from nowhere else.
I am thankful to any answer i get.