Ejemplo n.º 1
0
        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!");
        }