本文整理汇总了C#中LogLevel.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# LogLevel.ToString方法的具体用法?C# LogLevel.ToString怎么用?C# LogLevel.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LogLevel
的用法示例。
在下文中一共展示了LogLevel.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: _writer
void IActivityLoggerSink.OnEnterLevel( LogLevel level, string text )
{
TextWriter w = _writer();
w.Write( _prefix + "- " + level.ToString() + ": " );
_prefixLevel = _prefix + new String( ' ', level.ToString().Length + 4 );
w.WriteLine( text.Replace( Environment.NewLine, Environment.NewLine + _prefixLevel ) );
}
示例2: LogEntry
/// <summary>
/// Logs the specified level.
/// </summary>
/// <param name="level">The level.</param>
/// <param name="format">The format.</param>
/// <param name="objects">The objects.</param>
public static void LogEntry(LogLevel level, string format, params object[] objects)
{
lock (LOG) {
LOG.AppendFormat("{0:HH:mm:ss.ffff} [{1}] - ", DateTime.Now, level.ToString())
.AppendFormat(format, objects)
.AppendLine();
}
Console.Write("[{0}] ", level.ToString());
Console.WriteLine(format, objects);
}
示例3: Log
public LogEntry Log(string message, LogLevel logLevel = LogLevel.Verbose, string category = null)
{
if (string.IsNullOrWhiteSpace(message))
{
throw new ArgumentNullException("message");
}
var logRecord = new LogRecord
{
ID = Guid.NewGuid(),
Timestamp = DateTime.UtcNow,
Message = message,
LogLevelName = logLevel.ToString(),
LogLevelValue = (int)logLevel,
Category = category,
};
if (logLevel != LogLevel.None && logLevel >= LogLevel)
{
using (var db = new LogContext())
{
db.LogRecords.Add(logRecord);
db.SaveChangesSync();
}
}
return logRecord;
}
示例4: Log
/// <summary>
/// Logs a new message
/// </summary>
/// <param name="message">The string message to log</param>
/// <param name="level">LogLevel of this message</param>
public static void Log(string message, LogLevel level)
{
if (level > logLevel) return;
//Apply log color in console
switch (level)
{
case LogLevel.Error:
Console.ForegroundColor = ConsoleColor.Red;
break;
case LogLevel.Warning:
Console.ForegroundColor = ConsoleColor.Yellow;
break;
case LogLevel.Info:
Console.ForegroundColor = ConsoleColor.White;
break;
case LogLevel.Debug:
Console.ForegroundColor = ConsoleColor.DarkYellow;
break;
}
//Create prefix
string prefix = "(" + DateTime.Now.TimeOfDay + ") " + level.ToString().ToUpper() + ": ";
//Console
Console.Write(prefix);
Console.WriteLine(message);
//Write to file
if (!string.IsNullOrEmpty(fileUri)) File.AppendAllText(fileUri, prefix + message + "\n");
}
示例5: Log
public void Log(LogLevel lvl, string Message)
{
// loop over all lines in message
using (StringReader reader = new StringReader(Message))
{
string line;
while ((line = reader.ReadLine()) != null)
{
ListViewItem item = new ListViewItem(new string[] { DateTime.Now.ToString(), lvl.ToString(), line });
switch (lvl)
{
case LogLevel.Fatal:
item.BackColor = Color.DarkRed;
item.ForeColor = Color.White;
break;
case LogLevel.Error:
item.BackColor = Color.Red;
item.ForeColor = Color.White;
break;
case LogLevel.Warning:
item.BackColor = Color.Orange;
item.ForeColor = Color.White;
break;
}
listView1.Items.Add(item);
}
}
listView1.EnsureVisible(listView1.Items.Count - 1);
listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
}
示例6: LogLevelInfo
public LogLevelInfo(LogLevel level, Color color)
{
Level = level;
Name = level.ToString();
Color = color;
RangeMax = RangeMin = 0;
}
示例7: LogMessage
public override void LogMessage(string strLogMessage, LogLevel level) {
if (checkFilter(level)) {
return;
}
MessageBoxIcon icon;
switch(level){
case LogLevel.DEBUG:
case LogLevel.VERBOSE:
icon = MessageBoxIcon.Exclamation;
break;
case LogLevel.INFO:
case LogLevel.LOG:
icon = MessageBoxIcon.Information;
break;
case LogLevel.WARNING:
icon = MessageBoxIcon.Warning;
break;
case LogLevel.ERROR:
icon = MessageBoxIcon.Error;
break;
case LogLevel.CRITICAL:
icon = MessageBoxIcon.Stop;
break;
default:
icon = MessageBoxIcon.None;
break;
}
MessageBox.Show(strLogMessage, level.ToString(), MessageBoxButtons.OK, icon);
}
示例8: Message
private void Message(LogLevel level, string message)
{
foreach (var appender in _appenders)
{
if (appender.Level <= level) appender.Appender.Write(level.ToString().ToUpper() + " " + message);
}
}
示例9: Log
public static void Log(LogLevel level, String message)
{
Console.WriteLine ();
Console.WriteLine ("LEVEL: " + level.ToString());
Console.WriteLine (message);
Console.WriteLine ();
}
示例10: Log
private void Log(string message, LogLevel logLevel = LogLevel.Info)
{
var messageLog = new StringBuilder();
messageLog.Append("[ " + DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + " ]");
messageLog.Append("[" + logLevel.ToString().ToUpper() + "]");
messageLog.Append("[ " + _typeName + " ]");
messageLog.AppendFormat("[ Message: {0} ]", message);
System.Diagnostics.Debug.WriteLine(messageLog);
if (!LogConfiguration.LoggingIsEnabled) return;
if (LogConfiguration.LogType == LogType.InMemory)
{
if (LogList.Count == LogConfiguration.NumberOfRecords)
{
LogList.RemoveAt(0);
}
LogList.Add(messageLog.ToString());
}
else
{
WriteLogToFile(messageLog);
}
}
示例11: Print
public void Print(string mainLog, LogLevel level = LogLevel.INFO)
{
Debug.Log(mainLog);//给unity编辑器另外传一份log
CheckLogFileInfo();//检查是否已经更换日期了
try
{
string log = string.Format("[{0} {1}] : {2}", DateTime.Now.ToString("HH:mm:ss"), level.ToString(), mainLog);
//写入数据
lock (writeFileLock)
{
//写入数据
FileStream fs = new FileStream(logFileName, FileMode.Append);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine(log);
sw.Close();
fs.Close();
}
}
catch (IOException ex)
{
Debug.Log(ex.ToString());
}
}
示例12: Log
public void Log(LogLevel level, string format, params object[] args)
{
if (level > this.MinimumLogLevel)
{
return;
}
this.clock.Stop();
try
{
string message = args != null ? string.Format(format, args: args) : format;
ConsoleColor save = Console.ForegroundColor;
Console.ForegroundColor = MapColor(level);
const int LogLevelMaximumStringLength = 11; // Len(Information)
string levelAsString = level.ToString();
Console.Write(
"[{0}]{1} {2:00}.{3:000} ",
levelAsString,
string.Empty.PadLeft(LogLevelMaximumStringLength - levelAsString.Length),
this.clock.ElapsedMilliseconds / 1000,
this.clock.ElapsedMilliseconds % 1000);
Console.WriteLine(message);
Console.ForegroundColor = save;
}
finally
{
this.clock.Start();
}
}
示例13: WriteLog
private void WriteLog(LogLevel level, string log)
{
var path = string.Format(@"{0}{1}\{2}", YFK.Core.Configuration.YFKConfig.Instance.WebSetting.LogPath, DateTime.Now.ToString("yyyy年MM月dd日"), level.ToString());
if (path.Contains(":\\") == false)
{
if (System.Web.HttpContext.Current != null)
path = System.Web.HttpContext.Current.Server.MapPath(path);
else
path = AppDomain.CurrentDomain.BaseDirectory + path;
}
var fileName = string.Format("{0}.txt", DateTime.Now.ToString("HH"));
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
using (FileStream fs = new FileStream(Path.Combine(path, fileName), FileMode.Append, FileAccess.Write,
FileShare.Write, 1024, FileOptions.Asynchronous))
{
log = string.Format("================记录时间:{0}================\r\n{1}\r\n",
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), log);
byte[] buffer = System.Text.Encoding.UTF8.GetBytes(log + "\r\n");
IAsyncResult writeResult = fs.BeginWrite(buffer, 0, buffer.Length,
(asyncResult) =>
{
var fStream = (FileStream)asyncResult.AsyncState;
fStream.EndWrite(asyncResult);
},
fs);
fs.Close();
}
}
示例14: Log
public override void Log(LogLevel logLevel, string message, Exception ex = null)
{
if (logLevel > LogLevel)
return;
ConsoleLoggerLevelConfig levelConfig = LevelConfig[logLevel];
if (levelConfig.ForegroundColor.HasValue)
Console.ForegroundColor = levelConfig.ForegroundColor.Value;
if (levelConfig.BackgroundColor.HasValue)
Console.BackgroundColor = levelConfig.BackgroundColor.Value;
Console.WriteLine(Format, DateTime.Now, logLevel.ToString(), message);
if (ex != null && levelConfig.ShowException)
{
if (levelConfig.ShowStackTrace)
Console.WriteLine(ex);
else
Console.WriteLine("{0}: {1}", ex.GetType().Name, ex.Message);
}
Console.ResetColor();
}
示例15: DebugMessage
public void DebugMessage(string message, LogLevel level = LogLevel.Information)
{
if(! DebugMode)
return;
if(ShowTimestamps)
message = DateTime.Now.ToString("HH:mm:ss") + ": " + message;
switch(level)
{
case LogLevel.Information:
Debug.Log(message);
break;
case LogLevel.Warning:
Debug.LogWarning(message);
break;
case LogLevel.LogicError:
Debug.LogError(message);
break;
default:
throw new Exception("Unexpected log level! " + level.ToString()
+ Environment.NewLine + " message: " + message);
}
}