示例#1
0
        static void Main(string[] args)
        {
            LogHandlerBase infoHandler  = new InfoHandler();
            LogHandlerBase debugHandler = new DebugHandler();
            LogHandlerBase errorHandler = new ErrorHandler();
            LogHandlerBase fatalHandler = new FatalHandler();


            LogHandlerBase chainRoot = infoHandler;

            infoHandler.SetNext(debugHandler);
            debugHandler.SetNext(errorHandler);
            errorHandler.SetNext(fatalHandler);



            Console.WriteLine("Debug");
            chainRoot.log("hey", LOG_LEVEL.DEBUG);
            Console.WriteLine("==================");
            Console.WriteLine("Info");
            chainRoot.log("hey", LOG_LEVEL.INFO);
            Console.WriteLine("==================");
            Console.WriteLine("Fatal");
            chainRoot.log("hey", LOG_LEVEL.FATAL);
            Console.WriteLine("==================");
            Console.WriteLine("Error");
            chainRoot.log("hey", LOG_LEVEL.ERROR);
        }
示例#2
0
        static void Main(string[] args)
        {
            DebugHandle debug = new DebugHandle();
            InfoHandle  info  = new InfoHandle();
            ErrorHandle error = new ErrorHandle();
            FatalHandle fatal = new FatalHandle();

            LogHandlerBase chainRoot = debug;

            debug.SetNext(info);
            info.SetNext(error);
            error.SetNext(fatal);
            fatal.SetNext(null);

            // Using first chain: Debug --> Info --> Error --> Fatal
            chainRoot.PrintLog("This is a Fatal log", "Fatal");
            Console.WriteLine("==================");
            chainRoot.PrintLog("This is an Info log", "Info");
            Console.WriteLine("==================");
            chainRoot.PrintLog("This is an Debug log", "Debug");
            Console.WriteLine("==================");
            chainRoot.PrintLog("This is an Error log", "Error");
            Console.WriteLine("==================");
            chainRoot.PrintLog("This is an Error log", "AAA");
            Console.WriteLine("==================");

            //DebugHandle debug = new DebugHandle();
            //InfoHandle info = new InfoHandle();
            //ErrorHandle error = new ErrorHandle();
            //FatalHandle fatal = new FatalHandle();
            //
            chainRoot = fatal;
            fatal.SetNext(error);
            error.SetNext(info);
            info.SetNext(debug);
            debug.SetNext(null);

            // Using first chain: Fatal --> Error --> Info --> Debug
            chainRoot.PrintLog("This is a Fatal log", "Fatal");
            Console.WriteLine("==================");
            chainRoot.PrintLog("This is an Info log", "Info");
            Console.WriteLine("==================");
            chainRoot.PrintLog("This is an Debug log", "Debug");
            Console.WriteLine("==================");
            chainRoot.PrintLog("This is an Error log", "Error");
            Console.WriteLine("==================");
            chainRoot.PrintLog("This is an Error log", "AAA");
            Console.WriteLine("==================");
        }
 public void SetNext(LogHandlerBase next)
 {
     this.next = next;
 }