public void Write(object source, LogPrio priority, string message) { string msg = source + ": " + message; ILogger logger = ServiceRegistration.Get<ILogger>(); switch (priority) { case LogPrio.Trace: // Don't write trace messages (we don't support a trace level in MP - would have to map it to debug level) break; case LogPrio.Debug: logger.Debug(msg); break; case LogPrio.Info: logger.Info(msg); break; case LogPrio.Warning: logger.Warn(msg); break; case LogPrio.Error: logger.Error(msg); break; case LogPrio.Fatal: logger.Critical(msg); break; } }
public void Write(object source, LogPrio priority, string message) { switch (priority) { case LogPrio.Trace: case LogPrio.Debug: m_log.DebugFormat("[WORLDINVENTORY]: {0}: {1}", source.ToString(), message); break; case LogPrio.Error: m_log.ErrorFormat("[WORLDINVENTORY]: {0}: {1}", source.ToString(), message); break; case LogPrio.Info: m_log.InfoFormat("[WORLDINVENTORY]: {0}: {1}", source.ToString(), message); break; case LogPrio.Warning: m_log.WarnFormat("[WORLDINVENTORY]: {0}: {1}", source.ToString(), message); break; case LogPrio.Fatal: m_log.FatalFormat("[WORLDINVENTORY]: {0}: FATAL! - {1}", source.ToString(), message); break; default: m_log.DebugFormat("[WORLDINVENTORY]: {0}: {1}", source.ToString(), message); break; } return; }
public void Write(object source, LogPrio priority, string message) { string msg = source + ": " + message; ILogger logger = ServiceRegistration.Get <ILogger>(); switch (priority) { case LogPrio.Trace: // Don't write trace messages (we don't support a trace level in MP - would have to map it to debug level) break; case LogPrio.Debug: logger.Debug(msg); break; case LogPrio.Info: logger.Info(msg); break; case LogPrio.Warning: logger.Warn(msg); break; case LogPrio.Error: logger.Error(msg); break; case LogPrio.Fatal: logger.Critical(msg); break; } }
/// <summary> /// Get color for the specified logprio /// </summary> /// <param name="prio">prio for the log entry</param> /// <returns>A <see cref="ConsoleColor"/> for the prio</returns> public static ConsoleColor GetColor(LogPrio prio) { switch (prio) { case LogPrio.Trace: return(ConsoleColor.DarkGray); case LogPrio.Debug: return(ConsoleColor.Gray); case LogPrio.Info: return(ConsoleColor.White); case LogPrio.Warning: return(ConsoleColor.DarkMagenta); case LogPrio.Error: return(ConsoleColor.Magenta); case LogPrio.Fatal: return(ConsoleColor.Red); } return(ConsoleColor.Yellow); }
/// <summary> /// Logwriters the specified source. /// </summary> /// <param name="source">object that wrote the logentry.</param> /// <param name="prio">Importance of the log message</param> /// <param name="message">The message.</param> public void Write(object source, LogPrio prio, string message) { StringBuilder sb = new StringBuilder(); sb.Append(DateTime.Now.ToString()); sb.Append(" "); sb.Append(prio.ToString().PadRight(10)); sb.Append(" | "); #if DEBUG StackTrace trace = new StackTrace(); StackFrame[] frames = trace.GetFrames(); int endFrame = frames.Length > 4 ? 4 : frames.Length; int startFrame = frames.Length > 0 ? 1 : 0; for (int i = startFrame; i < endFrame; ++i) { sb.Append(frames[i].GetMethod().Name); sb.Append(" -> "); } #else sb.Append(System.Reflection.MethodBase.GetCurrentMethod().Name); sb.Append(" | "); #endif sb.Append(message); Console.ForegroundColor = GetColor(prio); Console.WriteLine(sb.ToString()); Console.ForegroundColor = ConsoleColor.Gray; }
public void Write(object source, LogPrio prio, string message) { switch (prio) { case LogPrio.Trace: //Log.DebugFormat("{0}: {1}", source, message); // This logging is very noisy break; case LogPrio.Debug: //Log.DebugFormat("{0}: {1}", source, message); // This logging is slightly noisy break; case LogPrio.Info: Log.Info(source + ": " + message); break; case LogPrio.Warning: Log.WarnFormat("{0}: {1}", source, message); break; case LogPrio.Error: Log.ErrorFormat("{0}: {1}", source, message); break; case LogPrio.Fatal: Log.FatalFormat("{0}: {1}", source, message); break; } }
/// <summary> /// Logwriters the specified source. /// </summary> /// <param name="source">object that wrote the logentry.</param> /// <param name="prio">Importance of the log message</param> /// <param name="message">The message.</param> public void Write(object source, LogPrio prio, string message) { StringBuilder sb = new StringBuilder(); sb.Append(DateTime.Now.ToString()); sb.Append(" "); sb.Append(prio.ToString().PadRight(10)); sb.Append(" | "); #if DEBUG StackTrace trace = new StackTrace(); StackFrame[] frames = trace.GetFrames(); int endFrame = frames.Length > 4 ? 4 : frames.Length; int startFrame = frames.Length > 0 ? 1 : 0; for (int i = startFrame; i < endFrame; ++i) { sb.Append(frames[i].GetMethod().Name); sb.Append(" -> "); } #else sb.Append(System.Reflection.MethodBase.GetCurrentMethod().Name); sb.Append(" | "); #endif sb.Append(message); Console.ForegroundColor = GetColor(prio); Console.WriteLine(sb.ToString()); Console.ForegroundColor = ConsoleColor.Gray; }
public void Write(object source, LogPrio priority, string message) { if (!_textBox.InvokeRequired && !_textBox.IsDisposed) { _textBox.AppendText("."); //_textBox.AppendText(String.Format("{0}:{1} on {2}" + Environment.NewLine, DateTime.Now, message, source ?? "<null>")); } else { Action<object, LogPrio, string> marshal = Write; _textBox.BeginInvoke(marshal, source, priority, message); } }
/// <summary> /// Neuer Log-Eintrag /// </summary> /// <param name="topic"></param> /// <param name="prio"></param> /// <param name="content"></param> public bool Log(LogTopic topic, LogPrio prio, string content) { const string query = "INSERT INTO Log(LogTime, Topic, Prio, Content) VALUES (CURRENT_TIMESTAMP, @topic, @prio, @content)"; Dictionary<string, object> args = new Dictionary<string, object> { { "@topic", topic.ToString() }, { "@prio", (ushort)prio }, { "@content", content } }; return SqlNonQuery(query, args); }
public void Write(object source, LogPrio prio, string message) { switch (prio) { case LogPrio.Trace: case LogPrio.Debug: Log.DebugFormat("{0}: {1}", source, message); break; case LogPrio.Info: Log.InfoFormat("{0}: {1}", source, message); break; case LogPrio.Warning: Log.WarnFormat("{0}: {1}", source, message); break; case LogPrio.Error: Log.ErrorFormat("{0}: {1}", source, message); break; case LogPrio.Fatal: Log.FatalFormat("{0}: {1}", source, message); break; } }
/// <summary> /// Neuer Log-Eintrag /// </summary> /// <param name="topic"></param> /// <param name="prio"></param> /// <param name="content"></param> public void Log(LogTopic topic, LogPrio prio, string content) { try { const string query = "INSERT INTO Log(LogTime, Topic, Prio, Content) VALUES (CURRENT_TIMESTAMP, @topic, @prio, @content)"; var args = new Dictionary <string, object> { { "@time", "" }, { "@topic", topic.ToString() }, { "@prio", (ushort)prio }, { "@content", content } }; using (SQLiteConnection con = new SQLiteConnection(Datasource)) { con.Open(); using (SQLiteCommand cmd = new SQLiteCommand(query, con)) { foreach (var pair in args) { cmd.Parameters.AddWithValue(pair.Key, pair.Value); } cmd.ExecuteNonQuery(); } } } catch (DllNotFoundException dll_ex) { Console.WriteLine(dll_ex.Message + "\r\n" + dll_ex.InnerException); Console.ReadKey(); } catch (Exception ex) { Console.WriteLine(ex.GetType() + "\r\n" + ex.Message); Console.ReadKey(); throw new Exception("Sql-Fehler Log() " + ex.GetType().Name); } }
/// <summary> /// 写日志消息,实现接口 /// </summary> public void Write(object source, LogPrio prio, string message) { StringBuilder sb = new StringBuilder(); sb.Append(DateTime.Now.ToString()); sb.Append(" "); sb.Append(prio.ToString().PadRight(5)); sb.Append(" ("); #if DEBUG StackTrace trace = new StackTrace(); StackFrame[] frames = trace.GetFrames(); int endFrame = frames.Length > 4 ? 4 : frames.Length; int startFrame = frames.Length > 0 ? 1 : 0; for (int i = startFrame; i < endFrame - 1; ++i) { sb.Append(frames[i].GetMethod().Name); sb.Append("."); } sb.Append(frames[endFrame - 1].GetMethod().Name); sb.Append(") "); #else sb.Append(System.Reflection.MethodBase.GetCurrentMethod().Name); sb.Append(" | "); #endif sb.Append(message); Console.ForegroundColor = GetColor(prio); Console.WriteLine(sb.ToString()); Console.ForegroundColor = ConsoleColor.Gray; //将日志写入目标文件 string logPath = @"Log\log.txt"; //文件相对路径 if (System.IO.File.Exists(logPath)) { System.IO.StreamWriter sw = new System.IO.StreamWriter(logPath, true, Encoding.UTF8); sw.WriteLine(sb); sw.Close(); } }
/// <summary> /// Neuer Log-Eintrag /// </summary> /// <param name="topic"></param> /// <param name="prio"></param> /// <param name="content"></param> public void Log(LogTopic topic, LogPrio prio, string content) { try { using (var connection = new SqliteConnection(DataSource)) { connection.Open(); var command = connection.CreateCommand(); command.CommandText = "INSERT INTO Log(LogTime, Topic, Prio, Content) VALUES (CURRENT_TIMESTAMP, @topic, @prio, @content)"; command.Parameters.AddWithValue("@topic", topic.ToString()); command.Parameters.AddWithValue("@prio", (ushort)prio); command.Parameters.AddWithValue("@content", content); command.ExecuteNonQuery(); } } catch (Exception ex) { throw new Exception("Sql-Fehler Log() " + ex.GetType().Name); } }
public void Write(object source, LogPrio prio, string message) { switch (prio) { case LogPrio.Trace: //Log.DebugFormat("{0}: {1}", source, message); // This logging is very noisy break; case LogPrio.Debug: //Log.DebugFormat("{0}: {1}", source, message); // This logging is slightly noisy break; case LogPrio.Info: Log.Info(source + ": " + message); break; case LogPrio.Warning: Log.WarnFormat("{0}: {1}", source, message); break; case LogPrio.Error: Log.ErrorFormat("{0}: {1}", source, message); break; case LogPrio.Fatal: Log.FatalFormat("{0}: {1}", source, message); break; } }
/// <summary> /// write an entry to the log file /// </summary> /// <param name="prio">importance of the message</param> /// <param name="message">log message</param> protected virtual void WriteLog(LogPrio prio, string message) { LogWriter.Write(this, prio, message); }
/// <summary> /// Used to log to void. /// </summary> /// <param name="prio"></param> /// <param name="message"></param> public static void Write(LogPrio prio, string message) { }
/// <summary> /// Writes everything to null /// </summary> /// <param name="source">object that wrote the logentry.</param> /// <param name="prio">Importance of the log message</param> /// <param name="message">The message.</param> public void Write(object source, LogPrio prio, string message) { }
/// <summary> /// Log something. /// </summary> /// <param name="prio">importance of log message</param> /// <param name="message">message</param> protected virtual void Write(LogPrio prio, string message) { _log.Write(this, prio, message); }
public void Write(object source, LogPrio priority, string message) { Logger.Write(source, priority, message); }
//#region Implementation of ILogWriter internal void Write(object source, LogPrio priority, string message) { WriteLine(priority + " " + message); }
/// <summary> /// write an entry to the log file /// </summary> /// <param name="prio">importance of the message</param> /// <param name="message">log message</param> protected virtual void WriteLog(LogPrio prio, string message) { LogWriter.Write(this, prio, message); }
public void Write(object source, LogPrio priority, string message) { traceLog(priority.ToString(), message); }
/// <summary> /// Log something. /// </summary> /// <param name="prio">importance of log message</param> /// <param name="message">message</param> protected virtual void Write(LogPrio prio, string message) { _log.Write(this, prio, message); }
/// <summary> /// write an entry to the log file /// </summary> /// <param name="source">object that wrote the message</param> /// <param name="prio">importance of the message</param> /// <param name="message">log message</param> public void WriteLog(object source, LogPrio prio, string message) { LogWriter.Write(source, prio, message); }
//private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); public void Write(object source, LogPrio priority, string message) { /* switch (priority) { case HttpServer.LogPrio.Debug: m_log.DebugFormat("[{0}]: {1}", source.ToString(), message); break; case HttpServer.LogPrio.Error: m_log.ErrorFormat("[{0}]: {1}", source.ToString(), message); break; case HttpServer.LogPrio.Info: m_log.InfoFormat("[{0}]: {1}", source.ToString(), message); break; case HttpServer.LogPrio.Warning: m_log.WarnFormat("[{0}]: {1}", source.ToString(), message); break; case HttpServer.LogPrio.Fatal: m_log.ErrorFormat("[{0}]: FATAL! - {1}", source.ToString(), message); break; default: break; } */ return; }
//#region Implementation of ILogWriter internal void Write(object source, LogPrio priority, string message) { WriteLine(priority + " " + message); }
/// <summary> /// write an entry to the log file /// </summary> /// <param name="source">object that wrote the message</param> /// <param name="prio">importance of the message</param> /// <param name="message">log message</param> public void WriteLog(object source, LogPrio prio, string message) { LogWriter.Write(source, prio, message); }
/// <summary> /// Get color for the specified logprio /// </summary> /// <param name="prio">prio for the log entry</param> /// <returns>A <see cref="ConsoleColor"/> for the prio</returns> public static ConsoleColor GetColor(LogPrio prio) { switch (prio) { case LogPrio.Trace: return ConsoleColor.DarkGray; case LogPrio.Debug: return ConsoleColor.Gray; case LogPrio.Info: return ConsoleColor.White; case LogPrio.Warning: return ConsoleColor.DarkMagenta; case LogPrio.Error: return ConsoleColor.Magenta; case LogPrio.Fatal: return ConsoleColor.Red; } return ConsoleColor.Yellow; }
public void Write(object source, LogPrio priority, string message) { Logger.Write(source, priority, message); }
/// <summary> /// Writes everything to null /// </summary> /// <param name="source">object that wrote the log entry.</param> /// <param name="prio">Importance of the log message</param> /// <param name="message">The message.</param> public void Write(object source, LogPrio prio, string message) {}
public void Write(object source, LogPrio priority, string message) { traceLog(priority.ToString(), message); }
public static void Log(string msg, LogPrio prio = LogPrio.Info) { Console.WriteLine(prio.ToString() + " : " + msg); }