本文整理汇总了C#中log4net.Core.Level类的典型用法代码示例。如果您正苦于以下问题:C# Level类的具体用法?C# Level怎么用?C# Level使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Level类属于log4net.Core命名空间,在下文中一共展示了Level类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LogMsg
public void LogMsg(Level level, string message)
{
//Debug.WriteLine( String.Format( "{0} {1}", level.ToString(), message ) );
if (level == Level.Info)
{
_log.Info(message);
}
else if (level == Level.Debug)
{
_log.Debug(message);
}
else if (level == Level.Error)
{
_log.Error(message);
}
else if (level == Level.Warn)
{
_log.Warn(message);
}
else
{
_log.Info(message);
}
}
示例2: Lookup
/// <summary>
/// Lookup the mapping for the specified level
/// </summary>
/// <param name="level">the level to lookup</param>
/// <returns>the <see cref="LevelMappingEntry"/> for the level or <c>null</c> if no mapping found</returns>
/// <remarks>
/// <para>
/// Lookup the value for the specified level. Finds the nearest
/// mapping value for the level that is equal to or less than the
/// <paramref name="level"/> specified.
/// </para>
/// <para>
/// If no mapping could be found then <c>null</c> is returned.
/// </para>
/// </remarks>
public LevelMappingEntry Lookup(Level level) {
if (m_entries != null)
foreach (LevelMappingEntry entry in m_entries)
if (level >= entry.Level)
return entry;
return null;
}
示例3: GetIndexForLevel
static int GetIndexForLevel(Level level)
{
if (level == Level.Info) return 2;
if (level == Level.Warn) return 3;
if (level == Level.Error || level == Level.Fatal) return 4;
return 1;
}
示例4: BindConsole
public static void BindConsole(PatternLayout layout = null, Level level = null)
{
layout = layout ?? new PatternLayout
{
ConversionPattern = "%date{ISO8601} %level %logger - %message%newline"
};
layout.ActivateOptions();
var consoleAppender = new ConsoleAppender
{
Name = "console",
Layout = layout
};
consoleAppender.ActivateOptions();
var hierarchy = (Hierarchy)LogManager.GetRepository();
if (hierarchy.Root.GetAppender("console") != null)
{
return;
}
hierarchy.Root.AddAppender(consoleAppender);
hierarchy.Root.Level = level ?? Level.Info;
hierarchy.Configured = true;
}
示例5: ConvertLevelToPriority
/// <summary>
/// Helper method to convert <see cref="Level"/> into a string ID that is mapped based upon the TOPS Syslog standard: https://confluence.mw.inc/display/TO/TOps+Syslog+Standard
/// </summary>
/// <param name="level"><see cref="Level"/> to convert to string</param>
/// <returns>string representing the syslog priority code as defined in the TOPS Syslog standard</returns>
public static string ConvertLevelToPriority(Level level)
{
if (level >= Level.Emergency)
{
return "128";
}
else if (level >= Level.Fatal)
{
return "130";
}
else if (level >= Level.Error)
{
return "131";
}
else if (level >= Level.Warn)
{
return "132";
}
else if (level >= Level.Info)
{
return "134";
}
else
{
return "135"; // debug
}
}
示例6: Log
private static void Log(string message, Level logLevel, string exceptionMessage, params object[] parameters)
{
if (WriteAsync)
{
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += LogEvent;
worker.RunWorkerAsync(new LogMessageSpec
{
ExceptionMessage = exceptionMessage,
LogLevel = logLevel,
Message = message,
Parameters = parameters,
Stack = new StackTrace(),
LogTime = DateTime.Now
});
}
else
{
PerformLog(new LogMessageSpec
{
ExceptionMessage = exceptionMessage,
LogLevel = logLevel,
Message = message,
Parameters = parameters,
Stack = new StackTrace(),
LogTime = DateTime.Now
});
}
}
示例7: PerformLog
private void PerformLog(Type type, Level level, Func<string> messageDelegate, Exception ex)
{
ThreadContext.Properties["subscriber"] = _subscriber.Email;
ThreadContext.Properties["subscriberId"] = _subscriber.Id;
_log.Logger.Log(type, level, messageDelegate.Invoke(), ex);
}
示例8: Setup
/// <summary>
/// Configures the log4net environment
/// </summary>
private void Setup(Level logLevel)
{
Directory.CreateDirectory(_logFolder);
var hierarchy = (Hierarchy)LogManager.GetRepository();
// Log to a file
var roller = new RollingFileAppender();
roller.AppendToFile = false;
roller.File = _logFile;
roller.Layout = new PatternLayout("%date %type.%method [%-5level] - %message%newline");
roller.MaxSizeRollBackups = 5;
roller.RollingStyle = RollingFileAppender.RollingMode.Size;
roller.StaticLogFileName = true;
roller.ActivateOptions();
hierarchy.Root.AddAppender(roller);
// Log to the visual studio console
var appender = new TraceAppender();
appender.ActivateOptions();
appender.Layout = new PatternLayout("%method (%line) %date [%-5level] - %message%newline");
hierarchy.Root.AddAppender(appender);
hierarchy.Root.Level = logLevel;
hierarchy.Configured = true;
}
示例9: InfoFormat
public void InfoFormat(string format, IMessage message, MessageId messageId, int messageSize, IList<Peer> peers, Level logLevel = null)
{
if (peers.Count == 0)
{
InfoFormat(format, message, messageId, messageSize);
return;
}
if (peers.Count == 1)
{
InfoFormat(format, message, messageId, messageSize, peerId: peers[0].Id);
return;
}
var logInfo = GetLogInfo(message);
if (!logInfo.Logger.IsInfoEnabled)
return;
var messageText = logInfo.GetMessageText(message);
var otherPeersCount = peers.Count - 1;
var peerIdText = otherPeersCount > 1
? peers[0].Id + " and " + otherPeersCount + " other peers"
: peers[0].Id + " and " + otherPeersCount + " other peer";
_logger.Logger.Log(_loggerType, logLevel ?? Level.Info, string.Format(format, messageText, messageId, messageSize, peerIdText), null);
}
示例10: FromLog4Net
internal static LogLevel FromLog4Net( Level level )
{
if ( level == Level.Error )
{
return LogLevel.Error;
}
else if ( level == Level.Warn )
{
return LogLevel.Warning;
}
else if ( level == Level.Notice )
{
return LogLevel.Notice;
}
else if ( level == Level.Info )
{
return LogLevel.Info;
}
else if ( level == Level.Debug )
{
return LogLevel.Debug;
}
else
{
throw new NotSupportedException( "LogLevel not supported: " + level );
}
}
示例11: ConfigureColoredConsoleAppender
private static void ConfigureColoredConsoleAppender(Level threshold)
{
var appender = new ColoredConsoleAppender
{
Threshold = threshold
};
appender.AddMapping(
new ColoredConsoleAppender.LevelColors
{
Level = Level.Debug,
ForeColor = ColoredConsoleAppender.Colors.White
});
appender.AddMapping(
new ColoredConsoleAppender.LevelColors
{
Level = Level.Info,
ForeColor = ColoredConsoleAppender.Colors.Green
});
appender.AddMapping(
new ColoredConsoleAppender.LevelColors
{
Level = Level.Warn,
ForeColor = ColoredConsoleAppender.Colors.Yellow | ColoredConsoleAppender.Colors.HighIntensity
});
appender.AddMapping(
new ColoredConsoleAppender.LevelColors
{
Level = Level.Error,
ForeColor = ColoredConsoleAppender.Colors.Red | ColoredConsoleAppender.Colors.HighIntensity
});
ConfigureAppender(appender);
}
示例12: LevelEvaluator
/// <summary>
/// Create a new evaluator using the specified <see cref="Level"/> threshold.
/// </summary>
/// <param name="threshold">the threshold to trigger at</param>
/// <remarks>
/// <para>
/// Create a new evaluator using the specified <see cref="Level"/> threshold.
/// </para>
/// <para>
/// This evaluator will trigger if the level of the event
/// passed to <see cref="IsTriggeringEvent(LoggingEvent)"/>
/// is equal to or greater than the <see cref="Threshold"/>
/// level.
/// </para>
/// </remarks>
public LevelEvaluator(Level threshold)
{
if (threshold == null)
throw new ArgumentNullException("threshold");
m_threshold = threshold;
}
示例13: TextWriterToLog4Net
public TextWriterToLog4Net(string loggerName, Level defaultLevel)
: base()
{
this.LoggerName = loggerName;
this.DefaultLevel = defaultLevel;
this.TrimHeaders = true;
}
示例14: WriteMessage
public static void WriteMessage(string message, Level level)
{
var stackTrace = new StackTrace(true);
var frame = stackTrace.GetFrame(1);
if (level == Level.Debug && Logger.IsDebugEnabled)
{
Logger.Debug(LoggerMessage.CreateMessage(message, frame));
}
if (level == Level.Error && Logger.IsErrorEnabled)
{
Logger.Error(LoggerMessage.CreateMessage(message, frame));
}
if (level == Level.Fatal && Logger.IsFatalEnabled)
{
Logger.Fatal(LoggerMessage.CreateMessage(message, frame));
}
if (level == Level.Warn && Logger.IsWarnEnabled)
{
Logger.Warn(LoggerMessage.CreateMessage(message, frame));
}
if (level == Level.Info && Logger.IsInfoEnabled)
{
Logger.Info(LoggerMessage.CreateMessage(message, frame));
}
}
示例15: LogControl
public LogControl()
{
InitializeComponent();
this.SuspendLayout();
var levels = new Level[] { Level.Debug, Level.Info, Level.Warn, Level.Error, Level.Fatal };
chkLevels = new List<CheckBox>(levels.Length);
foreach (var level in levels)
{
var chkLevel = new CheckBox();
chkLevel.Checked = level != Level.Debug;
chkLevel.Text = level.ToString();
chkLevel.Tag = level;
chkLevel.CheckedChanged += new EventHandler(chkLevel_CheckedChanged);
pnlFilter.Controls.Add(chkLevel);
chkLevels.Add(chkLevel);
}
btnClean = new Button();
btnClean.Margin = chkLevels.First().Margin;
btnClean.Text = "clean";
btnClean.Click += new EventHandler(btnClean_Click);
pnlFilter.Controls.Add(btnClean);
lblCount = new Label();
lblCount.Margin = chkLevels.First().Margin;
lblCount.Text = "0";
pnlFilter.Controls.Add(lblCount);
this.ResumeLayout(true);
}