コード例 #1
0
        /// <summary>
        /// Logs the message in the specified type of log.
        /// </summary>
        /// <param name="message">The message to be logged.</param>
        /// <param name="filename">The name of the log file.</param>
        /// <param name="l">The level of log to be written.</param>
        /// <param name="t">The type of log to be written.</param>
        public static void Log(string message, string filename, Level l = Level.NONE, Type t = Type.CONSOLE)
        {
            message = message.Trim(new char[] { '\n', '\r', ' ' }).TrimEnd(new char[] { '\t' }) + "\r\n";

            l = Logger.GetHighestLevel(l);

            if (l == Level.DEBUG)
            {
#if !DEBUG
                return;
#endif
            }

            if (l != Level.NONE)
            {
                message = l.ToString() + ": " + message;
            }

            if (((ushort)t & (ushort)Type.CONSOLE) > 0)
            {
                Console.Write(message);
            }

            if (((ushort)t & (ushort)Type.FILE) > 0)
            {
                bool writeComplete = false;
                while (!writeComplete)
                {
                    try
                    {
                        System.IO.File.AppendAllText(filename, message);
                        writeComplete = true;
                    }
                    catch (System.IO.IOException)
                    {
                        // Ignore the exception and retry the write.
                    }
                }
            }
        }
コード例 #2
0
ファイル: ConsoleOutputter.cs プロジェクト: barni211/Logger
 public void WriteLog(Level lvl, string value)
 {
     Console.WriteLine(lvl.ToString() + ": " + value + " WHEN: " + DateTime.Now);
 }
コード例 #3
0
ファイル: FileOutputter.cs プロジェクト: barni211/Logger
 public void WriteLog(Level lvl, string value)
 {
     File.AppendAllText(documentsPath + @"\LoggerOutputText.txt", lvl.ToString()
                        + ": " + value + " WHEN: " + DateTime.Now + Environment.NewLine);
 }