private static void LogError(string msg) { msg = LogAssist.CheckToBreakIntoDebugger(LogAssist.PrefixMemUsage(LogAssist.AppendStackTrace(msg))); ILog l = log; if (l != null) { l.Error(msg); } else { BufferMessage(msg); } #if TEST object l1 = new object(); object l2 = new object(); // Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start(); lock (l1) { // l1_clk.LockPerfTimerStop(); msg += "x"; // Utilities.LockPerfTimer l2_clk = Utilities.LockPerfChecker.Start(); System.Threading.Thread.Sleep(10 * 1000); // l2_clk.LockPerfTimerStop(); msg += "x"; } #endif }
private static void LogWarn(string msg) { msg = LogAssist.CheckToBreakIntoDebugger(LogAssist.PrefixMemUsage(LogAssist.AppendStackTrace(msg))); ILog l = log; if (l != null) { l.Warn(msg); } else { BufferMessage(msg); } }
public static LockPerfTimer Start() { LockPerfTimer rv = new LockPerfTimer { clk = Stopwatch.StartNew(), t = new Timer(), stackTrace = LogAssist.AppendStackTrace(null, "LockPerfChecker.Start").Trim(), obj_lock = new object(), }; rv.handler_ref = new ElapsedEventHandler((object source, ElapsedEventArgs e) => { Timer t = (source as Timer); lock (rv.obj_lock) { // when the event fired while the mainline code flow STOPPED the timer inside its critical section, // we should ignore this (queued) event: this sort of thing can easily occur while debugging the // application. if (rv.t == null) { t.Stop(); t.Close(); // return; } else if (t != rv.t) { throw new Exception("internal failure"); } } OnTimedEvent(rv, 1); }); // Hook up the Elapsed event for the timer. rv.t.Elapsed += rv.handler_ref; rv.t.AutoReset = true; // keep on firing event when lock remains stuck for the duration of multiple timeout intervals rv.t.Interval = 5 * 1000; rv.t.Enabled = true; return(rv); }
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); }