本文整理汇总了C#中LogLevel类的典型用法代码示例。如果您正苦于以下问题:C# LogLevel类的具体用法?C# LogLevel怎么用?C# LogLevel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LogLevel类属于命名空间,在下文中一共展示了LogLevel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteConsole
protected virtual void WriteConsole (LogLevel level, string tag, string message, Exception exc)
{
Console.WriteLine ("[{1}] {0}: {2}", level, tag, message);
if (exc != null) {
Console.WriteLine (exc.ToString ());
}
}
示例2: ToLog4Net
internal static Level ToLog4Net( LogLevel level )
{
if ( level == LogLevel.Error )
{
return Level.Error;
}
else if ( level == LogLevel.Warning )
{
return Level.Warn;
}
else if ( level == LogLevel.Notice )
{
return Level.Notice;
}
else if ( level == LogLevel.Info )
{
return Level.Info;
}
else if ( level == LogLevel.Debug )
{
return Level.Debug;
}
else
{
throw new NotSupportedException( "LogLevel not supported: " + level );
}
}
示例3: Log
public override void Log(LogLevel level, string msg, params object[] args)
{
lock (_lock)
{
var previous = Console.ForegroundColor;
switch (level)
{
case LogLevel.Debug:
Console.ForegroundColor = ConsoleColor.Blue;
break;
case LogLevel.Info:
Console.ForegroundColor = ConsoleColor.White;
break;
case LogLevel.Warning:
Console.ForegroundColor = ConsoleColor.Yellow;
break;
case LogLevel.Error:
Console.ForegroundColor = ConsoleColor.Red;
break;
case LogLevel.Fatal:
Console.ForegroundColor = ConsoleColor.Magenta;
break;
default:
break;
}
Console.WriteLine(NameFormatToPositionalFormat(msg), args);
Console.ForegroundColor = previous;
}
}
示例4: Write
public static void Write (LogLevel level, string msg, params object[] args)
{
lock (loggers) {
foreach (var l in loggers)
l.Write (level, msg, args);
}
}
示例5: Write
/// <summary>
/// ��¼��־�ķ���,�÷���Ĭ�ϰ���־��Ϣ��¼���ı��ļ���
/// </summary>
/// <param name="logMsg">��־�ı���Ϣ</param>
/// <param name="logLevel">��־�ȼ�</param>
public void Write(string logMsg, LogLevel logLevel)
{
MetaLog metaLog = new TxtMetaLog(logMsg);
metaLog.Level = logLevel;
this.Write(metaLog);
}
示例6: IsLoggingEnabled
public bool IsLoggingEnabled(LogLevel logLevel)
{
log4net.ILog logger;
if (_loggerName != null && _loggerName.Trim() != string.Empty)
logger = LogManager.GetLogger(_loggerName);
else
{
Type type = new StackFrame(_frameToSkip, false).GetMethod().DeclaringType;
logger = LogManager.GetLogger(type);
}
switch (logLevel)
{
case LogLevel.Debug:
return logger.IsDebugEnabled;
case LogLevel.Info:
return logger.IsInfoEnabled;
case LogLevel.Warn:
return logger.IsWarnEnabled;
case LogLevel.Error:
return logger.IsErrorEnabled;
case LogLevel.Fatal:
return logger.IsFatalEnabled;
case LogLevel.Off:
return false;
default:
throw new Exception(string.Format("Unrecognized log level '{0}'.", logLevel.ToString()));
}
}
示例7: Write
/// <summary>
/// Logs an entry to the source
/// </summary>
/// <param name="logLevel">Used level.</param>
/// <param name="msg">Message.</param>
/// <param name="exception">The exception (or null).</param>
public override void Write(LogLevel logLevel, string msg, Exception exception)
{
if (logLevel < _minLevel)
return;
_innerLogger.Write(logLevel, msg, exception);
}
示例8: SimpleLogItem
public SimpleLogItem(LogLevel level, string message, string info)
{
this.time = DateTime.Now;
this.level = level;
this.message = message;
this.info = info;
}
示例9: FileLog
public FileLog(string filePath, LogLevel minLevel = LogLevel.Info)
{
AttemptToCreateDirectory(filePath);
_logFileStream = new FileStream(filePath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
_minLevel = minLevel;
_logFile = filePath;
}
示例10: ActivityMonitorLineSender
/// <summary>
/// Used only by filtering extension methods (level is filtered and not None) or by static FakeLineSender (level is None).
/// </summary>
internal ActivityMonitorLineSender( IActivityMonitor monitor, LogLevel level, string fileName, int lineNumber )
: base( level, fileName, lineNumber )
{
Debug.Assert( FakeLineSender == null || ((level & LogLevel.IsFiltered) != 0 && MaskedLevel != LogLevel.None),
"The level is already filtered and not None or we are initializing the static FakeLineSender." );
_monitor = monitor;
}
示例11: ManagementConsoleLogTracer
public ManagementConsoleLogTracer(string logLevel)
{
switch (logLevel)
{
case "Fine":
_logLevel = LogLevel.Fine;
break;
case "Info":
_logLevel = LogLevel.Info;
break;
case "Fatal":
_logLevel = LogLevel.Fatal;
break;
case "Warning":
_logLevel = LogLevel.Warning;
break;
case "Debug":
_logLevel = LogLevel.Debug;
break;
case "Error":
_logLevel = LogLevel.Error;
break;
default:
throw new ArgumentException( "Unhandled log level: " + logLevel);
}
}
示例12: Log
public static void Log(LogLevel level, string message, Exception exception = null)
{
var builder = new StringBuilder();
builder.Append(DateTime.Now);
builder.Append(" [").Append(level.ToString().ToUpper()).Append("] ");
builder.Append(message);
//vamos imprimir para tela sem o stack track.
switch (level)
{
case LogLevel.Debug:
Console.ForegroundColor = ConsoleColor.DarkBlue;
break;
case LogLevel.Warn:
Console.ForegroundColor = ConsoleColor.Yellow;
break;
case LogLevel.Error:
Console.ForegroundColor = ConsoleColor.Red;
break;
}
Console.WriteLine(builder.ToString());
Console.ResetColor();
if (exception != null)
{
builder.Append('\n');
builder.Append("Caused by: ").Append(exception.Message).Append('\n');
builder.Append("Stack trace:\n");
builder.Append(exception.StackTrace);
}
Write(builder.ToString());
}
示例13: Log
// ReSharper disable ExplicitCallerInfoArgument
public static void Log(
this ILogger logger,
LogLevel logLevel,
Exception exception,
string message = null,
[CallerMemberName] string callerMemberName = null,
[CallerFilePath] string callerFilePath = null,
[CallerLineNumber] int callerLineNumber = 0)
{
if (exception == null)
{
throw new ArgumentNullException("exception");
}
if (logLevel != LogLevel.Audit && !logger.IsEnabled(logLevel))
{
return;
}
var logEntry = DefaultLogEntryFactory.Current.CreateLogEntry();
logEntry.Level = logLevel;
logEntry.SetException(exception);
logEntry.Message = message ?? exception.Message;
logger.LogAsync(logEntry, callerMemberName, callerFilePath, callerLineNumber);
}
示例14: Warning
/// <summary>
/// 初始化应用程序异常
/// </summary>
/// <param name="message">错误消息</param>
/// <param name="code">错误码</param>
/// <param name="level">日志级别</param>
/// <param name="exception">异常</param>
public Warning( string message, string code, LogLevel level, Exception exception )
: base( message ?? "", exception )
{
Code = code;
Level = level;
_message = GetMessage();
}
示例15: Log
public static void Log(LogLevel level, object sender, string message, params object[] args)
{
string typeName = (sender == null ? "(null)" : sender.GetType ().FullName);
LogEventInfo info = new LogEventInfo (_levelMap[level], typeName, string.Format (message, args));
info.Context.Add ("sender", sender);
_logger.Log (info);
}