Logger 2 : Log « Development Class « C# / C Sharp






Logger 2

      

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace tera.commons.utils
{
    public enum LogLevel
    {
        DEBUG,
        INFO,
        ERROR,
    FATAL,
    }

    public class Logger
    {
        public static LogLevel logLevel = 0;

        public static void debug(String msg)
        {
            log(LogLevel.DEBUG, msg);
        }

        public static void info(String msg)
        {
            log(LogLevel.INFO, msg);
        }

        public static void error(String msg)
        {
            log(LogLevel.ERROR, msg);
        }

    public static void fatal(String msg)
    {
      log(LogLevel.FATAL, msg);
    }
    
        private static void log(LogLevel level, String msg)
        {
            if (!logLevel.HasFlag(level))
                return;

            Console.WriteLine("{0} : {1}"
                , DateTime.Now.ToString("hh:mm:ss")
                , msg);
        }
    }
}

   
    
    
    
    
    
  








Related examples in the same category

1.Demonstrates registering and event source and writing to the Application LogDemonstrates registering and event source and writing to the Application Log
2.Add a EventLogTraceListener to the listener collection and writing error messages to the Application log
3.Test Log
4.Set Text Output To Event LogSet Text Output To Event Log
5.Log utility based on File with File.AppendAllText
6.Log message with StreamWriter
7.File Logger
8.Log error to a file
9.Logger
10.Log Utility
11.Log Exception with Event Log
12.Logger class
13.Instantiates a Trace log for detailed tracking of an application's internal activities.
14.Your own Logger
15.Implements a TextWriter for writing information to the debugger log.