log4net: Creating a logger dynamically, should I worry about anything?
Posted
by vtortola
on Stack Overflow
See other posts from Stack Overflow
or by vtortola
Published on 2010-04-15T19:00:17Z
Indexed on
2010/04/15
19:03 UTC
Read the original article
Hit count: 476
Hi,
I need to create loggers dynamically, so with a post from here and the help of reflector I have managed to create loggers dynamically, but I'd like to know if I should worry about something else ... I don't know wich implications can have do it.
public static ILog GetDyamicLogger(Guid applicationId)
{
Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
RollingFileAppender roller = new RollingFileAppender();
roller.LockingModel = new log4net.Appender.FileAppender.MinimalLock();
roller.AppendToFile = true;
roller.RollingStyle = RollingFileAppender.RollingMode.Composite;
roller.MaxSizeRollBackups = 14;
roller.MaximumFileSize = "15000KB";
roller.DatePattern = "yyyyMMdd";
roller.Layout = new log4net.Layout.PatternLayout();
roller.File = "App_Data\\Logs\\"+applicationId.ToString()+"\\debug.log";
roller.StaticLogFileName = true;
PatternLayout patternLayout = new PatternLayout();
patternLayout.ConversionPattern = "%date [%thread] %-5level %logger [%property{NDC}] - %message%newline";
patternLayout.ActivateOptions();
roller.Layout = patternLayout;
roller.ActivateOptions();
hierarchy.Root.AddAppender(roller);
hierarchy.Root.Level = Level.All;
hierarchy.Configured = true;
DummyLogger dummyILogger = new DummyLogger(applicationId.ToString());
dummyILogger.Hierarchy = hierarchy;
dummyILogger.Level = log4net.Core.Level.All;
dummyILogger.AddAppender(roller);
return new LogImpl(dummyILogger);
}
internal sealed class DummyLogger : Logger
{
// Methods
internal DummyLogger(string name)
: base(name)
{
}
}
Cheers.
© Stack Overflow or respective owner