public Log4NetLogger(string className, string serverName, int?logLevel) { string name = ""; if (serverName != null) { name = serverName + "_" + className + "Appender"; loggerName = serverName + "_" + className; } else { loggerName = className; name = className + "Appender"; } log4net.Appender.RollingFileAppender appender = Logger.GetAppenders(className, serverName); if (appender == null) { customAppender = new CustomFileAppender(className, serverName, logLevel); } log = log4net.LogManager.GetLogger(loggerName); // log4net.ILog[] loggers = log4net.LogManager.GetCurrentLoggers(); // log4net.Config.XmlConfigurator.Configure(); this.serverName = serverName; SetDefaultLogLevel(); SetDefaultConversionPattern(); if (logLevel != null) { SetLogLevel((int)logLevel); } }
public void Reset(string className, string serverName) { loggerName = serverName + "_" + className; log4net.Appender.RollingFileAppender appender = Logger.GetAppenders(className, serverName); if (appender == null) { customAppender = new CustomFileAppender(className, serverName, overriderLevel); } log = log4net.LogManager.GetLogger(loggerName); SetDefaultLogLevel(); SetDefaultConversionPattern(); if (overriderLevel != defaultLevel) { SetLogLevel(overriderLevel); } }
private void addNewAppender(int?logLevel, string pattern) { RollingFileAppender classAppender = Logger.GetAppenders(className, null); Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository(); PatternLayout patternLayout = new PatternLayout(); if (pattern == null) { if (classAppender != null) { if (classAppender.Layout != null) { log4net.Layout.PatternLayout layout = (log4net.Layout.PatternLayout)classAppender.Layout; patternLayout.ConversionPattern = layout.ConversionPattern; } else { patternLayout.ConversionPattern = fullMsgConversionPattern; } } else { patternLayout.ConversionPattern = fullMsgConversionPattern; } } else { patternLayout.ConversionPattern = pattern; } patternLayout.ActivateOptions(); RollingFileAppender roller = new RollingFileAppender(); roller.Layout = patternLayout; roller.Name = appenderName; roller.RollingStyle = RollingFileAppender.RollingMode.Composite; roller.PreserveLogFileNameExtension = true; roller.StaticLogFileName = false; roller.AppendToFile = true; roller.File = logFileName; roller.DatePattern = "yyyyMMdd-HH"; if (classAppender != null) { // roller.File = classAppender.File; roller.MaxSizeRollBackups = classAppender.MaxSizeRollBackups; roller.MaximumFileSize = classAppender.MaximumFileSize; roller.Threshold = classAppender.Threshold; } else { roller.MaxSizeRollBackups = 100; roller.MaximumFileSize = "10MB"; } roller.ActivateOptions(); log4net.ILog log = log4net.LogManager.GetLogger(serverName + "_" + className); ((log4net.Repository.Hierarchy.Logger)log.Logger).AddAppender(roller); // hierarchy.Root.AddAppender(roller); // hierarchy.Root.Level = GetLogLevel(logLevel); hierarchy.Configured = true; }