本文整理汇总了C#中LogLevels类的典型用法代码示例。如果您正苦于以下问题:C# LogLevels类的具体用法?C# LogLevels怎么用?C# LogLevels使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LogLevels类属于命名空间,在下文中一共展示了LogLevels类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LogMessage
public LogMessage(string msg)
{
this.level = LogLevels.Verbose;
this.msgText = msg;
this.subject = "unknown";
this.created = DateTime.Now;
}
示例2: LogFile
public static void LogFile(string entry, LogLevels level)
{
if (Silent)
{
return;
}
if (CurrentLevel > (byte)level)
{
return;
}
entry = DateTime.Now.TimeOfDay.ToString() + " " + Convert.ToString(Thread.CurrentThread.ManagedThreadId) + " " + entry;
Queue.Synchronized(logEntriesList).Enqueue(entry);
Monitor.Enter(logThread);
if(!logThread.IsAlive)
{
logThread.Start();
}
Monitor.Exit(logThread);
try
{
sm.Release();
}
catch
{
}
}
示例3: Log
public void Log(LogLevels logLevel, string str)
{
using (var sw = GetStreamWriter())
{
sw.WriteLine("{0}:{1:HH-mm-ss}: {2}", logLevel, DateTime.Now, str);
}
}
示例4: LogWithTags
public static void LogWithTags(this ExceptionlessClient client, string logMessage, string[] tags, string source = null, LogLevels level = LogLevels.Info)
{
if (client.LoggingEnabled())
client.CreateLog(source, logMessage, level.Text())
.AddTags(tags)
.Submit();
}
示例5: WriteText
public void WriteText(System.IO.TextWriter writer, LogLevels level, DateTime dateTime, string text)
{
string sLevel;
switch (level)
{
case LogLevels.Info:
default:
sLevel = "I";
break;
case LogLevels.Diagnostic:
sLevel = "D";
break;
case LogLevels.Warning:
sLevel = "W";
break;
case LogLevels.Error:
sLevel = "E";
break;
}
writer.WriteLine("{0}:{1} {2} [{4}]: {3}",
sLevel, dateTime.ToShortDateString(), dateTime.ToLongTimeString(),
text, Thread.CurrentThread.GetHashCode());
}
示例6: AppendEntry
public void AppendEntry(string sourceDomainName, global::System.Reflection.AssemblyName sourceAssembly, string sourceTypeName, string sourceMethodName, LogLevels level, DateTime timestamp, string message)
{
_logController.AppendEntry(sourceDomainName, sourceAssembly, sourceTypeName, sourceMethodName, level, timestamp, message);
System.sDomain[] doms = System.Domains;
foreach (System.sDomain dom in doms)
dom.Core.AppendEntry(sourceDomainName, sourceAssembly, sourceTypeName, sourceMethodName, level, timestamp, message);
}
示例7: Log
public static void Log(LogLevels level, string text)
{
#if LOG
if (!File.Exists(LogPath))
{
File.WriteAllText(LogPath, "Executable: " + Application.ExecutablePath + "\r\n" +
"Version: " + Application.ProductVersion + "\r\n" +
"Installed .Net Framework: " + typeof(object).Assembly.GetName().Version.ToString() + "\r\n" +
"OS: " + Environment.OSVersion.VersionString + "\r\n", Encoding.UTF8);
}
switch (level)
{
case LogLevels.Warning:
text = "[WARN] " + text;
break;
case LogLevels.Error:
text = "[ERRO] " + text;
break;
case LogLevels.Information:
default:
text = "[INFO] " + text;
break;
}
File.AppendAllLines(LogPath, new string[] { text }, Encoding.UTF8);
#endif
}
示例8: AddLog
/// <summary>
/// To record a message to the log.
/// </summary>
/// <param name="receiver">Logs receiver.</param>
/// <param name="level">The level of the log message.</param>
/// <param name="getMessage">The function returns the text for <see cref="LogMessage.Message"/>.</param>
public static void AddLog(this ILogReceiver receiver, LogLevels level, Func<string> getMessage)
{
if (receiver == null)
throw new ArgumentNullException(nameof(receiver));
receiver.AddLog(new LogMessage(receiver, receiver.CurrentTime, level, getMessage));
}
示例9: Write
/// <summary>
/// Writes a message to the log file.
/// </summary>
/// <param name="message">The message to write.</param>
/// <param name="level">The level of severity of the log message.</param>
public void Write(string message, LogLevels level)
{
lock (_lockObject)
{
if (_logLevel < level)
{
// This message is more detailed than the user wants logged.
return;
}
if (string.IsNullOrEmpty(_filename))
{
return;
}
using (var file = new StreamWriter(_filename, true))
{
file.WriteLine(
string.Concat(
DateTime.UtcNow.ToString("M/d/yyyy HH:mm:ss"),
" Level ",
Enum.GetName(typeof(LogLevels), level),
": ",
message));
}
}
}
示例10: WriteLog
private static void WriteLog(LogLevels level, string message)
{
if (!Directory.Exists(LogFolder))
{
Directory.CreateDirectory(LogFolder);
}
if (level >= Settings.settingsStore.logLevel)
{
string output;
if (Settings.settingsStore.useUTCTimeInLog)
{
output = "[" + DateTime.UtcNow.ToString("HH:mm:ss") + "][" + level.ToString() + "] : " + message;
}
else
{
output = "[" + DateTime.Now.ToString("HH:mm:ss") + "][" + level.ToString() + "] : " + message;
}
Console.WriteLine(output);
ClientHandler.SendConsoleMessageToAdmins(output);
try
{
lock (logLock) {
File.AppendAllText(LogFilename, output + Environment.NewLine);
}
}
catch (Exception e)
{
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine("Error writing to log file!, Exception: " + e);
Console.ForegroundColor = ConsoleColor.Gray;
}
}
}
示例11: LogLine
private static void LogLine(LogLevels level, string message)
{
if ((Level & level) == level)
{
LogStream.WriteLine(message);
}
}
示例12: Write
/// <summary>
/// Static function used to log textual information to the console output.
/// </summary>
/// <param name="it"></param>
/// <param name="text"></param>
/// <param name="level"></param>
internal static void Write(object it, string text, LogLevels level)
{
string label = "";
if (level > Level)
return;
switch (level)
{
case LogLevels.Debug:
label = "[DEBUG] ";
break;
case LogLevels.Error:
label = "[ERROR] ";
break;
case LogLevels.Info:
break;
case LogLevels.Warning:
label = "[WARNING] ";
break;
}
if (it == null)
Console.WriteLine(label + text);
else
Console.WriteLine(it.GetType().Name + ": " + label + text);
}
示例13: WriteLog
protected override void WriteLog(LogLevels logLevel, string logRecord)
{
if (!Preferences.AutoLog) return;
// 20140317
// turning off the logger
// switch (logLevel) {
// case LogLevels.Fatal:
// Logger.Fatal(logRecord);
// break;
// case LogLevels.Error:
// Logger.Error(logRecord);
// break;
// case LogLevels.Warn:
// Logger.Warn(logRecord);
// break;
// case LogLevels.Info:
// Logger.Info(logRecord);
// break;
// case LogLevels.Debug:
// Logger.Debug(logRecord);
// break;
// case LogLevels.Trace:
// Logger.Trace(logRecord);
// break;
// }
}
示例14: VisualLog
public static void VisualLog(LogLevels loglevel, string type, String ex)
{
// create output to console
TextWriterTraceListener console = new TextWriterTraceListener();
console.Writer = Console.Out;
Trace.Listeners.Add(console);
//output error
if (System.Diagnostics.Trace.Listeners.Count > 0)
{
Trace.Write(new TraceData(loglevel, DateTime.Now, type, ex));
}
//close streams
console.Close();
if (!ApplicationType.GetApplicationType().Equals(ApplicationType.Type.Console))
{
//messagebox
MessageBoxIcon icon = MessageBoxIcon.None;
switch (loglevel)
{
case LogLevels.Error:
icon = MessageBoxIcon.Error;
break;
case LogLevels.Warning:
icon = MessageBoxIcon.Warning;
break;
case LogLevels.Info:
icon = MessageBoxIcon.Information;
break;
}
MessageBox.Show(ex, type, MessageBoxButtons.OK, icon);
}
}
示例15: AltLog
/// <summary>
/// Logs a message to the database logger.
/// If logger not defined, logs to the console.
/// </summary>
public static void AltLog(LogLevels eventType, int id, string message, bool forceconsole = false)
{
if (!forceconsole && Logger != null)
Logger.TraceEvent(eventType, id, message);
else
Console.WriteLine(eventType.ToString() + " " + id + " " + LMLoggers.LognLM.FlattenChars(message));
}