예제 #1
0
        public void Can_write_to_log_using_default_methods()
        {
            if (File.Exists("log.txt"))
            {
                File.Delete("log.txt");
            }

            for (var i = 0; i < 10; i++)
            {
                logger.Info("Hello {0}!", i);
            }

            try
            {
                throw new Exception("Test exception");
            }
            catch (Exception ex)
            {
                logger.ErrorException("It failed :(", ex);
            }

            var test = File.ReadAllText("log.txt");

            Assert.True(File.Exists("log.txt"));
            Assert.True(test.Length > 0);
        }
        /// <summary>
        /// 写入日志
        /// </summary>
        /// <param name="info"></param>
        protected override void Write(T info)
        {
            switch (info.Sevenrity)
            {
            case Sevenrity.Debug:
                if (_logger.IsDebugEnabled)
                {
                    _logger.Debug(info);
                }
                break;

            case Sevenrity.Error:
                if (_logger.IsErrorEnabled)
                {
                    _logger.Error(info);
                }
                break;

            case Sevenrity.Fatal:
                if (_logger.IsFatalEnabled)
                {
                    _logger.Fatal(info);
                }
                break;

            case Sevenrity.Info:
                if (_logger.IsInfoEnabled)
                {
                    _logger.Info(info);
                }
                break;

            case Sevenrity.Trace:
                if (_logger.IsWarnEnabled)
                {
                    _logger.Info(info);
                }
                break;

            case Sevenrity.Warn:
                if (_logger.IsWarnEnabled)
                {
                    _logger.Warn(info);
                }
                break;
            }
        }
예제 #3
0
        /// <summary>
        ///     记录日志
        /// </summary>
        /// <param name="loggerLevels">日志级别</param>
        /// <param name="message">日志消息</param>
        public override void Log(LoggerLevels loggerLevels, object message)
        {
            switch (loggerLevels)
            {
            case LoggerLevels.Trace:
                _logger.Trace(message);
                break;

            case LoggerLevels.Debug:
                _logger.Debug(message);
                break;

            case LoggerLevels.Info:
                _logger.Info(message);
                break;

            case LoggerLevels.Warn:
                _logger.Warn(message);
                break;

            case LoggerLevels.Error:
                _logger.Error(message);
                break;

            case LoggerLevels.Fatal:
                _logger.Fatal(message);
                break;

            default:
                break;
            }
            ExcutedOnLog(loggerLevels, message);
        }
예제 #4
0
        private void Info(string?message,
                          [CallerMemberName] string?previousMethodName = null,
                          [CallerLineNumber] int callermemberlineNo    = 0,
                          [CallerFilePath] string?calledFilePath       = null)
        {
            if (string.IsNullOrEmpty(message))
            {
                NullError(nameof(message));
                return;
            }

            LogModule?.Info($"{message}");
        }
예제 #5
0
        private static void SetupLogging()
        {
            NLog.LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration(
                Path.Combine(
                    Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                    "nlog.config"
                    )
                );

            Common.Logging.LogManager.Adapter =
                new Common.Logging.NLog.NLogLoggerFactoryAdapter(
                    new Common.Logging.Configuration.NameValueCollection()
            {
                { "configType", "EXTERNAL" }
            });

            _Log = global::NLog.LogManager.GetCurrentClassLogger();

            _Log.Info("{0} v{1} - {2} starting.", ProgramName, ProgramVersion, InformationalVersion);
            _Log.Info("CommandLine: {0}", Environment.CommandLine);
            _Log.Info("CommandLineArgs: {0}", Environment.GetCommandLineArgs().Aggregate((cur, next) => cur + "," + next));
            _Log.Info("CurrentBaseDirectory: {0}", AppDomain.CurrentDomain.BaseDirectory);
        }
예제 #6
0
 public void Info(string msg) => nLogger.Info(msg);
예제 #7
0
 public void Info(string message)
 {
     logger.Info(message);
 }
예제 #8
0
 private void Log(string text)
 {
     Logger.Info(text);
 }
예제 #9
0
 public void Information(string message)
 {
     _logger.Info(message);
 }
예제 #10
0
 /// <inheritdoc/>
 public void Info(string message) => _log.Info(message);
예제 #11
0
 public void LogInfo(string message)
 {
     _functionLogger.Info(message, _source);
     _redisLogger.Info(message);
 }
예제 #12
0
 public void Info(string text)
 {
     Logger.Info(text);
 }
예제 #13
0
파일: NLogLog.cs 프로젝트: gcheney/Burrows
 public void Info(LogOutputProvider messageProvider)
 {
     _log.Info(ToGenerator(messageProvider));
 }