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; } }
/// <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); }
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}"); }
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); }
public void Info(string msg) => nLogger.Info(msg);
public void Info(string message) { logger.Info(message); }
private void Log(string text) { Logger.Info(text); }
public void Information(string message) { _logger.Info(message); }
/// <inheritdoc/> public void Info(string message) => _log.Info(message);
public void LogInfo(string message) { _functionLogger.Info(message, _source); _redisLogger.Info(message); }
public void Info(string text) { Logger.Info(text); }
public void Info(LogOutputProvider messageProvider) { _log.Info(ToGenerator(messageProvider)); }