Ejemplo n.º 1
0
 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;
   }
 }
Ejemplo n.º 2
0
        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;
        }
Ejemplo n.º 3
0
            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;
                }
            }
Ejemplo n.º 4
0
        /// <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);
        }
Ejemplo n.º 5
0
        /// <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;
        }
Ejemplo n.º 6
0
        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;
            }
        }
Ejemplo n.º 7
0
        /// <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;
        }
Ejemplo n.º 8
0
 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);
     }
 }
Ejemplo n.º 9
0
        /// <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);
        }
Ejemplo n.º 10
0
 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;
     }
 }
Ejemplo n.º 11
0
        /// <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);
            }
        }
Ejemplo n.º 12
0
        /// <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();
            }
        }
Ejemplo n.º 13
0
        /// <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);
            }
        }
Ejemplo n.º 14
0
 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;
     }
 }
Ejemplo n.º 15
0
 /// <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)
 {
 }
Ejemplo n.º 17
0
 /// <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)
 {
 }
Ejemplo n.º 18
0
 /// <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);
 }
Ejemplo n.º 19
0
 public void Write(object source, LogPrio priority, string message)
 {
     Logger.Write(source, priority, message);
 }
Ejemplo n.º 20
0
        //#region Implementation of ILogWriter

        internal void Write(object source, LogPrio priority, string message)
        {
            WriteLine(priority + " " + message);
        }
Ejemplo n.º 21
0
		/// <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);
 }
Ejemplo n.º 23
0
 /// <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);
 }
Ejemplo n.º 24
0
 /// <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);
 }
Ejemplo n.º 25
0
        //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;
        }
Ejemplo n.º 26
0
        //#region Implementation of ILogWriter

        internal void Write(object source, LogPrio priority, string message)
        {
            WriteLine(priority + " " + message);
        }
Ejemplo n.º 27
0
		/// <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);
		}
Ejemplo n.º 28
0
        /// <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;
        }
Ejemplo n.º 29
0
 public void Write(object source, LogPrio priority, string message)
 {
     Logger.Write(source, priority, message);
 }
Ejemplo n.º 30
0
 /// <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)
 {}
Ejemplo n.º 31
0
 public void Write(object source, LogPrio priority, string message)
 {
     traceLog(priority.ToString(), message);
 }
Ejemplo n.º 32
0
 public static void Log(string msg, LogPrio prio = LogPrio.Info)
 {
     Console.WriteLine(prio.ToString() + " : " + msg);
 }