private void InitLogging(string confDir) { if (Runtime.GetProperty("log4j.configuration") == null) { Runtime.SetProperty("log4j.defaultInitOverride", "true"); bool fromClasspath = true; FilePath log4jConf = new FilePath(confDir, Log4jProperties).GetAbsoluteFile(); if (log4jConf.Exists()) { PropertyConfigurator.ConfigureAndWatch(log4jConf.GetPath(), 1000); fromClasspath = false; } else { ClassLoader cl = Thread.CurrentThread().GetContextClassLoader(); Uri log4jUrl = cl.GetResource(Log4jProperties); if (log4jUrl != null) { PropertyConfigurator.Configure(log4jUrl); } } Log = LoggerFactory.GetLogger(typeof(KMSWebApp)); Log.Debug("KMS log starting"); if (fromClasspath) { Log.Warn("Log4j configuration file '{}' not found", Log4jProperties); Log.Warn("Logging with INFO level to standard output"); } } else { Log = LoggerFactory.GetLogger(typeof(KMSWebApp)); } }
/// <exception cref="System.Exception"/> public static void UpdateLog4jConfiguration(Type targetClass, string log4jPath) { Properties customProperties = new Properties(); FileInputStream fs = null; InputStream @is = null; try { fs = new FileInputStream(log4jPath); @is = targetClass.GetResourceAsStream("/log4j.properties"); customProperties.Load(fs); Properties originalProperties = new Properties(); originalProperties.Load(@is); foreach (KeyValuePair <object, object> entry in customProperties) { originalProperties.SetProperty(entry.Key.ToString(), entry.Value.ToString()); } LogManager.ResetConfiguration(); PropertyConfigurator.Configure(originalProperties); } finally { IOUtils.CloseQuietly(@is); IOUtils.CloseQuietly(fs); } }
public virtual void SetUp() { originalOut = System.Console.Error; memOut = new ByteArrayOutputStream(); filterOut = new TestKMSAudit.FilterOut(memOut); capturedOut = new TextWriter(filterOut); Runtime.SetErr(capturedOut); PropertyConfigurator.Configure(Thread.CurrentThread().GetContextClassLoader ().GetResourceAsStream("log4j-kmsaudit.properties")); this.kmsAudit = new KMSAudit(1000); }
/// <summary>Initializes Log4j logging.</summary> /// <exception cref="ServerException">thrown if Log4j could not be initialized.</exception> /// <exception cref="Org.Apache.Hadoop.Lib.Server.ServerException"/> protected internal virtual void InitLog() { VerifyDir(logDir); LogManager.ResetConfiguration(); FilePath log4jFile = new FilePath(configDir, name + "-log4j.properties"); if (log4jFile.Exists()) { PropertyConfigurator.ConfigureAndWatch(log4jFile.ToString(), 10 * 1000); //every 10 secs log = LoggerFactory.GetLogger(typeof(Org.Apache.Hadoop.Lib.Server.Server)); } else { Properties props = new Properties(); try { InputStream @is = GetResource(DefaultLog4jProperties); try { props.Load(@is); } finally { @is.Close(); } } catch (IOException ex) { throw new ServerException(ServerException.ERROR.S03, DefaultLog4jProperties, ex.Message , ex); } PropertyConfigurator.Configure(props); log = LoggerFactory.GetLogger(typeof(Org.Apache.Hadoop.Lib.Server.Server)); log.Warn("Log4j [{}] configuration file not found, using default configuration from classpath" , log4jFile); } }