public Log(LogModes logMode) { this.logInformation = new LogInformation(); this.assertion = new InstanceAnswerPro.Debug.Assertion(this); this.logModeField = logMode; Instance = this; }
public MinVersionTool(string filename, LogModes logMode) { this.logMode = logMode; DateTime start = DateTime.Now; ParseMap(filename); Versions minversion = AnalyseEntities(); DateTime end= DateTime.Now; TimeSpan diff = end.Subtract(start); string prefix = ""; if (diff.Milliseconds < 100) prefix += "0"; if (diff.Milliseconds < 10) prefix += "0"; Console.WriteLine("Finished parsing \"" + filename + "\" in " + diff.Seconds + "." + prefix + diff.Milliseconds + "s"); Console.WriteLine("\n================"); Console.WriteLine("minversion = " + VersionsStrings[(int)minversion]); Console.WriteLine("================"); Console.WriteLine("\n\npress any key to continue..."); Console.ReadKey(true); }
public LogMan(string logName, LogLevel logLevel = LogLevel.All, bool showLevel = true, bool showDateTime = true, bool showLogName = true, string dateTimeFormat = DEFAULT_LOGLINE_TIME_FORMAT) { StartedAt = DateTime.Now; LogModes = GlobalLogMode; if (LogModes.HasFlag(LogMode.CommonLog)) { try { CommonLogger = GetLogger(logName); } catch (Exception ex) { LogModes = (GlobalLogMode ^ LogMode.CommonLog) | LogMode.Native; Info(INTERNAL_ERROR_STR + "Failure initalizing CommonLog,use native mode instead!", ex); } } LogLevel = logLevel; ShowLevel = showLevel; ShowDateTime = showDateTime; ShowLogName = showLogName; DateTimeFormat = dateTimeFormat; Name = logName; RenewLogWriter(); //Register this Logman instance to a global static dictionary, if new instance use exisiting name, the old record would be overwritten. Loggers.AddOrUpdate(logName, this, (k, v) => { v.Dispose(); return(this); }); Info("[LogMan]\tOK!"); }
public MinVersionTool(string filename, LogModes logMode) { this.logMode = logMode; DateTime start = DateTime.Now; ParseMap(filename); Versions minversion = AnalyseEntities(); DateTime end = DateTime.Now; TimeSpan diff = end.Subtract(start); string prefix = ""; if (diff.Milliseconds < 100) { prefix += "0"; } if (diff.Milliseconds < 10) { prefix += "0"; } Console.WriteLine("Finished parsing \"" + filename + "\" in " + diff.Seconds + "." + prefix + diff.Milliseconds + "s"); Console.WriteLine("\n=================="); Console.WriteLine("minversion = " + VersionsStrings[(int)minversion]); Console.WriteLine("=================="); Console.WriteLine("\n\npress any key to continue..."); Console.ReadKey(true); }
public T Logger <T>(string function, Func <T> tryHandler, ErrorHandles errorHandle = ErrorHandles.Continue, LogModes logMode = LogModes.Debug, Func <Exception, T> catchHandler = null, Action finalHandler = null) { try { if (_log != null) { _log.Debug(function); } return(tryHandler()); } catch (Exception ex) { _log.Error(function + "失败", ex); if (catchHandler != null) { var result = catchHandler(ex); return(result); } if (errorHandle == ErrorHandles.Throw) { throw ex; } return(default(T)); } finally { finalHandler?.Invoke(); } }
/// <summary> /// 记录日志 /// </summary> /// <param name="log">日志内容</param> /// <param name="function">功能名称</param> /// <param name="errorHandleType">异常处理方式</param> /// <param name="tryHandle">委托(Try)</param> /// <param name="catchHandle">委托(Catch)</param> /// <param name="finallyHandle">委托(Finally)</param> public void Logger(string function, Action tryHandler, ErrorHandles errorHandle = ErrorHandles.Continue, LogModes logMode = LogModes.Debug, Action <Exception> catchHandler = null, Action finallyHandler = null) { try { if (_log != null) { _log.Debug(function); } tryHandler(); } catch (Exception ex) { _log.Error(function + "失败", ex); catchHandler?.Invoke(ex); if (errorHandle == ErrorHandles.Throw) { throw ex; } } finally { finallyHandler?.Invoke(); } }
public void LogMsg(LogModes mode, LogLevel level, object msg) { string strLogFileName = String.Empty; switch (mode) { case LogModes.UI: strLogFileName = "RBAI.UI.log"; break; case LogModes.REPO: strLogFileName = "RBAI.Repository.log"; break; case LogModes.ERROR: strLogFileName = "RBAI.Error.log"; break; } log4net.GlobalContext.Properties["LogFileName"] = strLogFileName; log4net.Config.XmlConfigurator.Configure(); ILog log = LogManager.GetLogger(typeof(Logger)); switch (level) { case LogLevel.DEBUG: log.Debug(msg); break; case LogLevel.INFO: log.Info(msg); break; case LogLevel.WARN: log.Warn(msg); break; case LogLevel.ERROR: log.Error(msg); break; case LogLevel.FATAL: log.Fatal(msg); break; } }
public static void RemoveLogEntriesByMode(LogModes mode) { LogEntry.Internal_RemoveLogEntriesByMode((int)mode); }