Example #1
0
        public void WriteFormattedLog(Enums.LogLevels level, string text)
        {
            string pretext;

            switch (level)
            {
            case Enums.LogLevels.TRACE:
                pretext = System.DateTime.Now.ToString(DatetimeFormat) + " [TRACE]   ";
                break;

            case Enums.LogLevels.INFO:
                pretext = System.DateTime.Now.ToString(DatetimeFormat) + " [INFO]    ";
                break;

            case Enums.LogLevels.DEBUG:
                pretext = System.DateTime.Now.ToString(DatetimeFormat) + " [DEBUG]   ";
                break;

            case Enums.LogLevels.WARNING:
                pretext = System.DateTime.Now.ToString(DatetimeFormat) + " [WARNING] ";
                break;

            case Enums.LogLevels.ERROR:
                pretext = System.DateTime.Now.ToString(DatetimeFormat) + " [ERROR]   ";
                break;

            case Enums.LogLevels.FATAL:
                pretext = System.DateTime.Now.ToString(DatetimeFormat) + " [FATAL]   ";
                break;

            default:
                pretext = "";
                break;
            }
            WriteLine(pretext + text);
        }
Example #2
0
        /// <summary>
        ///     Write <paramref name="message"/> to log
        /// </summary>
        /// <param name="message"></param>
        /// <param name="logLevel"></param>
        public void WriteLog(string message, Enums.LogLevels logLevel = Enums.LogLevels.Info)
        {
            switch (logLevel)
            {
            case Enums.LogLevels.Debug:
            {
                ThreadContext.Properties["logPath"] = Constants.Paths.Debug;
            }
            break;

            case Enums.LogLevels.Info:
            {
                ThreadContext.Properties["logPath"] = Constants.Paths.Info;
            }
            break;

            case Enums.LogLevels.Warn:
            {
                ThreadContext.Properties["logPath"] = Constants.Paths.Warn;
            }
            break;

            case Enums.LogLevels.Error:
            {
                ThreadContext.Properties["logPath"] = Constants.Paths.Error;
            }
            break;

            case Enums.LogLevels.Fatal:
            {
                ThreadContext.Properties["logPath"] = Constants.Paths.Fatal;
            }
            break;
            }
            _logger = LogManager.GetLogger(GetCaller());
            XmlConfigurator.Configure();
            switch (logLevel)
            {
            case Enums.LogLevels.Debug:
            {
                _logger.Debug(message);
            }
            break;

            case Enums.LogLevels.Info:
            {
                _logger.Info(message);
            }
            break;

            case Enums.LogLevels.Warn:
            {
                _logger.Warn(message);
            }
            break;

            case Enums.LogLevels.Error:
            {
                _logger.Error(message);
            }
            break;

            case Enums.LogLevels.Fatal:
            {
                _logger.Fatal(message);
            }
            break;
            }

            LogManager.GetRepository().Shutdown();
        }