private static bool Init() { bool go; lock (log4net_loaded_lock) { go = (null == __log && log4net_loaded && !log4net_init_pending && !log4net_has_shutdown); if (go) { log4net_init_pending = true; // block simultaneous execution of the rest of the code in Init() } } if (go) { try { BasicConfigurator.Configure(); XmlConfigurator.Configure(); ILog l = LogManager.GetLogger(typeof(Logging)); lock (log4net_loaded_lock) { __log = l; } // as per https://stackoverflow.com/questions/28723920/check-whether-log4net-xmlconfigurator-succeeded // // log4net must have picked up the configuration or it will not function anyhow //if (!LogManager.GetRepository().Configured) { // log4net not configured foreach (var message in LogManager.GetRepository().ConfigurationMessages) { // evaluate configuration message LogLog logInitMsg = message as LogLog; BufferMessage(String.Format("log4net config: {0}", logInitMsg?.Message ?? message)); } } } catch (Exception ex) { BufferException(ex); } } bool rv; lock (log4net_loaded_lock) { if (go) { log4net_init_pending = false; // de-block } // return value: TRUE when success rv = (null != __log); } // only log/yak about initialization success when it actually did happen just above: if (rv) { Debug("Logging initialised at {0}", LogAssist.AppendStackTrace(null, "get_log")); Info("Logging initialised."); // thread safety: move and reset the pending message buffer/list List <LogBufEntry> lst = new List <LogBufEntry>(); lock (log4net_loaded_lock) { if (init_ex_list != null && init_ex_list.Count > 0) { // move list lst = init_ex_list; init_ex_list = null; } } if (lst.Count > 0) { Error("--- Logging early bird log messages: ---"); foreach (LogBufEntry ex in lst) { if (ex.ex != null) { if (ex.message != null) { Error(ex.ex, "{0}", ex.message); } else { Error(ex.ex, "Logger init failure?"); } } else { Info("{0}", ex.message); } } lst.Clear(); Error("-- Logging early bird log messages done. ---"); } } return(rv); }
/// <summary> /// Test whether the log4net-based log system has been loaded and set up and if so, enable the use of that logging system. /// /// Up to that moment, all Logging APIs will log to a memory buffer/queue which will written to the logging system /// once it is loaded, set up and active. /// </summary> public static void TriggerInit() { bool go; lock (log4net_loaded_lock) { go = (null == __log && !log4net_loaded && !log4net_init_pending && !log4net_has_shutdown); if (go) { log4net_init_pending = true; // block simultaneous execution of the rest of the code in TriggerInit() } } if (go) { bool we_are_ready_for_the_next_phase = false; try { // test if log4net assembly is loaded and ready: Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); bool active = false; foreach (Assembly assembly in assemblies) { if (assembly.FullName.StartsWith("log4net")) { active = true; break; } } if (active) { // as per https://stackoverflow.com/questions/28723920/check-whether-log4net-xmlconfigurator-succeeded // // log4net must have picked up the configuration or it will not function anyhow if (!LogManager.GetRepository().Configured) { // log4net not configured foreach (var message in LogManager.GetRepository().ConfigurationMessages) { // evaluate configuration message LogLog logInitMsg = message as LogLog; BufferMessage(String.Format("log config: {0}", logInitMsg?.Message ?? message)); } } we_are_ready_for_the_next_phase = true; } } finally { // make sure the pending flag is reset whenever we leave this block lock (log4net_loaded_lock) { log4net_loaded = we_are_ready_for_the_next_phase; log4net_init_pending = false; // de-block } } } }
public LogReceivedEventArgs(log4net.Util.LogLog loglog) { this.loglog = loglog; }